[英]Angular 1.3 filter list of objects with array attribute
我希望有一個人可以幫助我。 對於我當前在angular 1.3中的項目,我使用以下列表:
$scope.myList = [{
id: "obj1",
content: [{
id: 1,
name: 'attr 1'
}, {
id: 2,
name: 'attr 2'
}, {
id: 3,
name: 'attr 3'
}]
}, {
id: "obj2",
content: [{
id: 4,
name: 'attr 4'
}, {
id: 5,
name: 'attr 5'
}, {
id: 6,
name: 'attr 6'
}]
}, {
id: "obj3",
content: [{
id: 7,
name: 'attr 7'
}, {
id: 8,
name: 'attr 8'
}, {
id: 9,
name: 'attr 9'
}]
}];
我想獲得內容數組中ID為X的對象。
我使用了此ng-repeat:
<ul>
<li ng-repeat="item in myList | filter: {content: [{id:1}]}">
{{item}}
</li>
</ul>
當我使用id:1,id:4或id:7時,它可以工作,但不適用於其他id ...
有任何想法嗎?
編輯
我最終發現了問題的原因,我使用的是angular 1.3.0。 升級到1.3.11后,它可以正常工作!!
您可以根據嵌套屬性進行過濾,如下所示:
<li ng-repeat="item in myList | filter: {content: {id: '1'}}">
{{item}}
</li>
重要的是要注意,您將獲得的“對象”(具有ID X)將在item
級別。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.