bklups bklups - 4 months ago 21
Javascript Question

AngularJS filter array in array from json data

My data called from a JSON is very simple.

I want to filter all data where the id of events is 13

My json provides from

[...] $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"}
]
}
]


I try to display with :

<ion-item collection-repeat="thing in things | filter:{events.id:'13'}">
{{thing.id}}
</ion-item>

Answer

Very 1st thing you need to correct you JSON format, like events11, events12 & events13 should be key value pair like such "events": "11", "events": "12" & "events": "13".

Then you could use deep filter like below.

Markup

<ion-item collection-repeat="thing in things | filter:{events: {id:'13'}}">
    {{thing.id}}
</ion-item>

Plunkr here

Comments