After writing some code to search Reddit's API with a specific query, I now want it to display comments as well. Inside my $.getJSON
statement that retrieves each title/post based on the search query, I have the following nested code block. The goal is to show the comment tree for each result that is found, which is why it's placed within the original $.getJSON
statement.
$.getJSON("http://www.reddit.com/r/" + sub + "/comments/" + id + ".json?", function (data){
$.each(data.data.children, function (i, item) {
var comment = item.data.body;
var author = item.data.author;
var postcomment = '<p>[Author]' + author + '<br>' + comment + '</p>';
results.append(postcomment);
});
});
I'm concerned that I might be structuring the $.each
statement incorrectly. I'm basically replicating what I did for the other getJSON statement. Do you have any suggestions or ideas?