2

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>
0

3 Answers 3

2

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

Sign up to request clarification or add additional context in comments.

7 Comments

@JLRishe because haven't had changed in json, the JSON in question is invalid, you could check attached plunkr, though thanks for heads up man, cheers :)
I had fixed the broken JSON, but it must have not been working because my fiddle had Angular 1.0.1. I guess the deep filtering feature was added in some later version of Angular.
yes, If I remeber correctly, it have added since 1.3+
Thanks @PankajParkar : instead of having an integer for id {id:'13'} i want to have a dynamic value {events.id'} how do that ? (to have a page per events.id)
I don't really fully understand.
|
0

You could filter directly in the controller when instantiating the scope variable:

$scope.things = things.filter(obj => obj.id==='13');

Comments

-1
 <ion-item collection-repeat="thing in things">
    <span ng-repeat="event in thing.events" ng-if="event.id='13'"
        {{thing.id}}
 </ion-item>

Basically two loops with an ng-if for the inner loop to check if the even's id is 13.

2 Comments

what do you mean by item.id == '13'?
my bad, just a typo, changed it now

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.