Filter on nested JSON


#1

I’m trying to make a filter on a nested JSON. When I use the default filter:query, it looks at all the propertys in the JSON, I only want to look at a few. This is my JSON:

{         
         "id":"4",         
         "user":{            
            "firstName":"First",            
            "lastName":"Name",
            "address":"address",
            etc
         }

<ion-item ng-repeat="user in data | filter:{'user.lastName':query}" item="item"> doesn’t work, when I use “id” instead of user.lastName it works fine. Without the ’ ’ it doesn’t work either, and filter:{user:{lastName:query}} doesn’t work either.
Any thoughts ? Thanks in advance


#2

It’s likely you are going to need to create a custom fliter:


#3

That worked, thanks a lot. Was hoping I could use the default angularjs filter, but apparently not.


#4

The default AngularJS filters only work on arrays, not objects - if you could re-structure your object you could use the default filters much like in your original code, but you’ll have more flexibility with a custom filter.


#5

When I added track by id, this solution does not work… :confounded: