Javascript 来自json数据的数组中的AngularJS筛选器数组
我从JSON调用的数据非常简单 我想过滤事件id为13的所有数据 My json提供了fromJavascript 来自json数据的数组中的AngularJS筛选器数组,javascript,angularjs,ionic-framework,angularjs-ng-repeat,angularjs-filter,Javascript,Angularjs,Ionic Framework,Angularjs Ng Repeat,Angularjs Filter,我从JSON调用的数据非常简单 我想过滤事件id为13的所有数据 My json提供了from[…]$scope.things=things [ { "id":"1", "title":"title1", "events":[ {"id":"11", "events11"}, {"id":"12", "events12"}
[…]$scope.things=things
[
{
"id":"1",
"title":"title1",
"events":[
{"id":"11",
"events11"},
{"id":"12",
"events12"}
]
},{
"id":"2",
"title":"title2",
"events":[
{"id":"11",
"events11"},
{"id":"13",
"events13"}
]
}
]
我尝试显示以下内容:
<ion-item collection-repeat="thing in things | filter:{events.id:'13'}">
{{thing.id}}
</ion-item>
{{thing.id}
实例化范围变量时,您可以直接在控制器中进行筛选:
$scope.things = things.filter(obj => obj.id==='13');
您可以使用ng if和一个助手函数进行尝试:
<ion-item collection-repeat="thing in things" ng-if="getEventInThing(thing, '13')">
{{thing.id}}
</ion-item>
您需要更正JSON格式的第一件事是,
events11
,events12
和events13
应该是键值对,比如“events”:“11”
,“events”:“12”&“events”:“13”
然后你可以使用下面的深层过滤器
标记
<ion-item collection-repeat="thing in things | filter:{events: {id:'13'}}">
{{thing.id}}
</ion-item>
{{thing.id}
@JLRishe因为json中没有更改,所讨论的json是无效的,您可以检查附加的plunkr,尽管感谢heads up man,干杯:)我已经修复了损坏的json,但它一定没有工作,因为我的小提琴有Angular 1.0.1。我猜深度过滤功能是在Angular的某个更高版本中添加的。是的,如果我没记错的话,它是从1.3+开始添加的。谢谢@PankajParkar:我想有一个动态值{id:'13'}
,而不是一个整数作为id{events.id'}
怎么办?(每个events.id有一个页面)我真的不太明白。你说的item.id='13'
是什么意思?我的错,只是一个打字错误,现在改了
<ion-item collection-repeat="thing in things | filter:{events: {id:'13'}}">
{{thing.id}}
</ion-item>
<ion-item collection-repeat="thing in things">
<span ng-repeat="event in thing.events" ng-if="event.id='13'"
{{thing.id}}
</ion-item>