【发布时间】:2015-01-24 01:25:51
【问题描述】:
我将 2 个数组传递给我的视图。我希望我的嵌套循环仅显示它的 parent_id 值与 parent.id 匹配的位置。例如。
arr1 = {"0":{"id":326,"parent_id":0,"title":"Mellow Mushroom voucher","full_name":"Patrick","message":"The voucher says $10 Voucher; some wording on the printout says, \"This voucher is valid for $20 Pizza\" but my purchase price or amount paid also says $20. Shouldn't that be $10","type":"Deals"}};
arr2 = {"0":{"id":327,"parent_id":326,"title":"Re: Mellow Mushroom voucher","full_name":"Patrick Williams","message":"Some message here","type":null};
...
<div data-ng-repeat = "parent in arr1">
<span>{{parent.title}}<span>
<div data-ng-repeat="child in arr2 | only-show-where-child.parent_id == parent.id">
<li>{{child.body}}</li>
</div>
</div>
在将它传递给角度之前,我应该在节点中过滤对象吗?谢谢!
【问题讨论】:
-
我假设 arr1 和 arr2 是真正的数组而不仅仅是对象,如果是这样,那么你可以编辑你的代码吗?我自己会,但如果这实际上是问题的一部分,我不想这样做。
-
它们是对象,对不起!对每个对象进行了编辑。
标签: angularjs filter nested repeat