2015-11-04 77 views
0

我有一個數據模型是一個數組有一些對象。這些對象可能包含一些孩子objects.so如何在一個NG重複attribue運行在這兩種NG-重複.. 這裏是一個examle JSON角度ng-重複子對象

[ 
    { 
     "foo": "bar", 
     "values": null, 
     "children": [ 
      { 
       "foo": "bar", 
       "values": null, 
       "children": null 
      } 
     ] 
    }, 
    { 
     "foo": "bar", 
     "children": [ 
      { 
       "id": 1, 
       "ques": "something" 
      } 
     ] 
    } 
] 
+0

你的孩子對象有不同的atttirubtes的 – Sajeetharan

+0

可能的複製[Angularjs:理解遞歸指令(http://stackoverflow.com/questions/19125551/angularjs-understanding-a-recursive-directive) – Grundy

+0

@ user332863請接受正確的答案或告訴我們什麼是不工作的。 – AntiHeadshot

回答

0

例如:

<div ng-repeat="object in objects"> 
    <div ng-repeat="child in object"> 
    {{child}} 
    </div> 
</div> 

哪裏對象是您從主機接收的主要對象,例如http請求,而child是對象內的子對象。你可以像對象的孩子一樣深入孩子的對象。

你的情況:

<div ng-repeat="object in objects"> 
    {{object.foo}} {{object.values}} 
    <div ng-repeat="child in object"> 
    {{child.id}} {{child.ques}} 
    </div> 
</div> 
0

使用首選收集,處理庫將其轉換成孩子的數組。

例如,在lodash_.flatten(_.pluck(yourArray, 'children')) (我認爲有這方面的一個鏈接的版本嗎?)

然後,只需遍歷它正常。

可以在控制器中完成操作,以在範圍上設置變量,或者在範圍上定義一個函數,或者在html中內聯完成操作。