小编dav*_*vet的帖子

与父值匹配的角度嵌套ng-repeat过滤器项

我传递了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>
Run Code Online (Sandbox Code Playgroud)

这是角度中的可能/最佳实践吗?我应该在将节点传递给角度之前过滤节点中的对象吗?谢谢!

nested filter repeat angularjs

8
推荐指数
2
解决办法
9844
查看次数

标签 统计

angularjs ×1

filter ×1

nested ×1

repeat ×1