具有数组属性的对象的 Angular 1.3 过滤器列表 [英] Angular 1.3 filter list of objects with array attribute
问题描述
我希望有人能帮助我.对于我当前在 angular 1.3 中的项目,我正在使用这个列表:
I hope someone can help me. For my current project in angular 1.3 I'm using this list:
$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 的对象.
I would like to get the object which has the id X in the content array.
我使用了这个 ng-repeat:
I used this ng-repeat:
<ul>
<li ng-repeat="item in myList | filter: {content: [{id:1}]}">
{{item}}
</li>
</ul>
当我使用 id:1、id:4 或 id:7 时,它有效,但不适用于其他 id...
When I use id:1, id:4 or id:7 it works, but not for the other ids...
有人有什么想法吗?
编辑
我终于找到了导致问题的原因,我使用的是 angular 1.3.0.升级到 1.3.11 后就成功了!!
I FINALLY found out what caused the problem, I was using angular 1.3.0. After upgrading to 1.3.11 it worked!!
推荐答案
您可以像这样根据嵌套属性进行过滤:
You can filter based on nested properties like so:
<li ng-repeat="item in myList | filter: {content: {id: '1'}}">
{{item}}
</li>
请务必注意,您将获得的对象"(具有 id X)将处于 item
级别.
It's important to note that the "object" (that has the id X) you'll get will be at the item
level.
这篇关于具有数组属性的对象的 Angular 1.3 过滤器列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!