2015-11-04 71 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中内联完成操作。