0

jsFiddle:http: //jsfiddle.net/FRQ9b/

使用 reddit 的 json 结果。这是我使用 3 个回复(嵌套)创建的示例帖子。

?([
     {
        "kind":"Listing",
        "data":{
           "modhash":"",
           "children":[
              {
                 "kind":"t3",
                 "data":{
                    "domain":"self.testapiarena",
                    "banned_by":null,
                    "media_embed":{

                    },
                    "subreddit":"testapiarena",
                    "selftext_html":"<!-- SC_OFF --><div class=\"md\"><p>Example of selfpost text</p>\n</div><!-- SC_ON -->",
                    "selftext":"Example of selfpost text",
                    "likes":null,
                    "link_flair_text":null,
                    "id":"v4bux",
                    "clicked":false,
                    "title":"testing nested comments",
                    "num_comments":3,
                    "score":1,
                    "approved_by":null,
                    "over_18":false,
                    "hidden":false,
                    "thumbnail":"",
                    "subreddit_id":"t5_2ub3u",
                    "edited":false,
                    "link_flair_css_class":null,
                    "author_flair_css_class":null,
                    "downs":0,
                    "saved":false,
                    "is_self":true,
                    "permalink":"/r/testapiarena/comments/v4bux/testing_nested_comments/",
                    "name":"t3_v4bux",
                    "created":1339833041.0,
                    "url":"http://www.reddit.com/r/testapiarena/comments/v4bux/testing_nested_comments/",
                    "author_flair_text":null,
                    "author":"elzi",
                    "created_utc":1339807841.0,
                    "media":null,
                    "num_reports":null,
                    "ups":1
                 }
              }
           ],
           "after":null,
           "before":null
        }
     },
     {
        "kind":"Listing",
        "data":{
           "modhash":"",
           "children":[
              {
                 "kind":"t1",
                 "data":{
                    "body":"This is a parent comment",
                    "edited":false,
                    "subreddit_id":"t5_2ub3u",
                    "author_flair_css_class":null,
                    "created":1339833054.0,
                    "replies":{
                       "kind":"Listing",
                       "data":{
                          "modhash":"",
                          "children":[
                             {
                                "kind":"t1",
                                "data":{
                                   "body":"This is one comments below the parent level",
                                   "edited":false,
                                   "subreddit_id":"t5_2ub3u",
                                   "author_flair_css_class":null,
                                   "created":1339833067.0,
                                   "replies":{
                                      "kind":"Listing",
                                      "data":{
                                         "modhash":"",
                                         "children":[
                                            {
                                               "kind":"t1",
                                               "data":{
                                                  "body":"A comment below the first child.",
                                                  "edited":false,
                                                  "subreddit_id":"t5_2ub3u",
                                                  "author_flair_css_class":null,
                                                  "created":1339833090.0,
                                                  "replies":"",
                                                  "banned_by":null,
                                                  "downs":0,
                                                  "author":"elzi",
                                                  "created_utc":1339807890.0,
                                                  "body_html":"<div class=\"md\"><p>A comment below the first child.</p>\n</div>",
                                                  "link_id":"t3_v4bux",
                                                  "parent_id":"t1_c517ue3",
                                                  "approved_by":null,
                                                  "likes":null,
                                                  "author_flair_text":null,
                                                  "id":"c517ujo",
                                                  "subreddit":"testapiarena",
                                                  "num_reports":null,
                                                  "ups":1,
                                                  "name":"t1_c517ujo"
                                               }
                                            }
                                         ],
                                         "after":null,
                                         "before":null
                                      }
                                   },
                                   "banned_by":null,
                                   "downs":0,
                                   "author":"elzi",
                                   "created_utc":1339807867.0,
                                   "body_html":"<div class=\"md\"><p>This is one comments below the parent level</p>\n</div>",
                                   "link_id":"t3_v4bux",
                                   "parent_id":"t1_c517uas",
                                   "approved_by":null,
                                   "likes":null,
                                   "author_flair_text":null,
                                   "id":"c517ue3",
                                   "subreddit":"testapiarena",
                                   "num_reports":null,
                                   "ups":1,
                                   "name":"t1_c517ue3"
                                }
                             }
                          ],
                          "after":null,
                          "before":null
                       }
                    },
                    "banned_by":null,
                    "downs":0,
                    "author":"elzi",
                    "created_utc":1339807854.0,
                    "body_html":"<div class=\"md\"><p>This is a parent comment</p>\n</div>",
                    "link_id":"t3_v4bux",
                    "parent_id":"t3_v4bux",
                    "approved_by":null,
                    "likes":null,
                    "author_flair_text":null,
                    "id":"c517uas",
                    "subreddit":"testapiarena",
                    "num_reports":null,
                    "ups":1,
                    "name":"t1_c517uas"
                 }
              }
           ],
           "after":null,
           "before":null
        }
     }
  ])

这是一个 jsfiddle,我已经走了多远:http: //jsfiddle.net/FRQ9b/

谁能告诉我如何获得下面的嵌套回复?所以卡住了。谢谢!

4

1 回答 1

2

好的,我设法为您创建了一个快速演示。您可以在这里查看 [jsfiddle 代码。][1] [1]:http: //jsfiddle.net/nickadeemus2002/qzNad/

我让它处理一些基于 json 数据结构的基本循环。这仅用于演示目的,因为您必须重构一些代码。但是,我让它工作,所以你可以看到如何访问数据。

于 2012-06-16T07:00:00.183 回答