2013-08-28 75 views
1

我試圖遍歷數據是這樣的:AngularJS NG-重複過的數據以#鍵

{ 
      "request": "Stream/GetDigest", 
      "response": { 
       "success": true, 
       "content": { 
        "0": { 
         "artifact_id": "36", 
         "timestamp": "2013-08-20 11:59:00", 
         "modified": "2013-08-20 11:59:00", 
         "text": "Why did the last one BLAHHHHH duplicate? I don't think I clicked it twice...", 
         "author_desc": "", 
         "object_type": "artifact", 
         "comments": [] 
        }, 
        "1": { 
         "artifact_id": "35", 
         "timestamp": "2013-08-20 11:57:51", 
         "modified": "2013-08-20 11:57:51", 
         "text": "This is a new artifact for a new day.", 
         "author_desc": "", 
         "object_type": "artifact", 
         "comments": [] 
        }, 
        "2": { 
         "artifact_id": "34", 
         "timestamp": "2013-08-20 11:57:50", 
         "modified": "2013-08-20 11:57:50", 
         "text": "This is a new artifact for a new day.", 
         "author_desc": "", 
         "object_type": "artifact", 
         "comments": [] 
        }, 
        "3": { 
         "artifact_id": "30", 
         "timestamp": "2013-08-19 13:15:32", 
         "modified": "2013-08-20 11:01:12", 
         "text": "This is some awesome text that we want to display!", 
         "author_desc": "", 
         "object_type": "artifact", 
         "comments": { 
          "5": { 
           "artifact_id": "30", 
           "comment_id": "5", 
           "user_id": "5", 
           "author_desc": "Michael C.", 
           "timestamp": "2013-08-19 16:18:12", 
           "private": "1", 
           "reported": 0, 
           "moderated": 0, 
           "banned": 0, 
           "text": "This is a createComment artifact" 
          }, 
          "6": { 
           "artifact_id": "30", 
           "comment_id": "6", 
           "user_id": "5", 
           "author_desc": "Michael C.", 
           "timestamp": "2013-08-20 11:01:12", 
           "private": "1", 
           "reported": 0, 
           "moderated": 0, 
           "banned": 0, 
           "text": "This is another comment" 
          } 
         } 
        }, 
        "4": { 
         "artifact_id": "33", 
         "timestamp": "2013-08-19 15:25:11", 
         "modified": "2013-08-19 15:25:11", 
         "text": "Kitten Ipsum dolor sit amet urna, bibendum life litora quis wish vel happy litora kitties laoreet buddy Praesent her. Lure, local ipsum amet urna molestie Nam. Snuggliest sed first chuf his cat kitten, ac climb the curtains cat eget sagittis et front", 
         "author_desc": "", 
         "object_type": "artifact", 
         "comments": [] 
        } 
       } 
      } 
     } 

的目標是遍歷response.content#部分。目前,我通過控制器傳遞內容(嬰兒的步驟 - 我是新的)通過GetDigest變量。所以我NGrepeater看起來是這樣的:

<li ng-repeat="thing in GetDigestList.response.content"> 

如何我可以把它遍歷這個JSON的子板塊?

謝謝!

+2

如果內容是數組,則會更好 – Abilash

+0

不幸的是,我沒有對數據源的任何控制。 – flashpunk

回答

2

是這樣的嗎?

<li ng-repeat="(index, content) in GetDigestList.response.content"> 
    <!-- ... --> 
</li> 

http://jsfiddle.net/Tdzhv/

+1

就是這樣!謝謝! – flashpunk

+0

Np。 +1也會很好:) –

+0

@flashpunk:另外請注意'ng-repeat'期望它的密鑰是唯一的。你必須使用'track by'來指定一個索引變量。儘管如此,在Angular的'ng-repeat'文檔中發現了這個信息的金塊和對這個SO問題的答案。這是值得檢查;)http://docs.angularjs.org/api/ng.directive:ngRepeat –

0

如果你能擁有的內容作爲數組,你可以使用由每個指令產生的$索引。 但爲了以防萬一,請檢查$ index是否不返回字符串鍵。