Reputation: 6246
I have an array of objects (~650) in the format
[1: {firstName: "Hello",
lastName: "World",
shortName: "h.world",
...some other items
},
2: {firstName: "John",
lastName: "Doe",
shortName: "j.doe",
...some other items
}]
And I need to filter through the list based on a text input, which should search firstName+ " "+lastName
. So searching He
or Hello W
will return Hello World
, and searching Hellow
wouldn't return it (case doesn't matter). What's the best way to filter the array? I've seen Angulars filter method but I've not yet worked out how to do it.
EDIT What I have
<div ng-controller="NotesCtrl">
<p>Search for a user to see there sessions and notes</p>
<input type="text" id="user" ng-model="search.firstName" />
{literal}
<ul>
<li ng-repeat="u in users | filter:search">{{u.activeDirectoryName}}</li>
</ul>
{/literal}
</div>
From what I've read that should work, but the list doesn't filter. Do I need to do anything in the controller to get this to work?
Answer: Turns out even though in PHP my data was an array, in Javascript it was an object, changed it around a bit so it came through as an array and it seems to be working now.
Upvotes: 0
Views: 118
Reputation: 7279
In your case, search
should be a function in your controller that takes each item in the array and returns true
or false
depending if it passes the filter or not.
Upvotes: 1