【发布时间】:2014-03-02 00:59:50
【问题描述】:
所以我编写了一些基于查询搜索 reddits api 的代码,并且我希望它也显示 cmets。我在$.getJSON 语句中嵌套了以下代码,该语句根据您的搜索查询提取每个标题/帖子,现在我想为找到的每个结果显示评论树(因此我将它嵌套在我原来的 getJSON 语句中)
$.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)
});
});
我有一种感觉,我可能将 $.each 语句的结构错误或其他什么。我只是按照我为其他 getJSON 语句所做的操作。有什么想法吗?
【问题讨论】:
-
我还在 JSONViewer 上注意到,当我使用 url 检索 cmets 时,它会拉出 [0] 和 [1],0 包含帖子的原始数据,1 包含 cmets 的数据.也许我需要指定查看 [1]?
标签: javascript json api getjson reddit