javascript - Filter array by common object property in Angular.js? -
i've been struggling on few hours. situation is, have app, receives data people in json format:
"people": [ { "name": "ivan", "city": "moscow", "country": "russia" }, { "name": "john", "city": "seattle", "country": "united states" }, { "name": "michael", "city": "seattle", "country": "united states" } ]
and need filter them groups based on city (to displayed in dropdown <ul>
s. i.e. user clicks "seattle" , <li>
s john , michael displayed.
how can done?
use angular-filter grouping. view code this:
<ul ng-repeat="(key, value) in people | groupby: 'city'"> city: {{ key }} <li ng-repeat="person in value"> person: {{ person.name }} </li> </ul>
here's plunker.
Comments
Post a Comment