I am trying to apply a filter to a JSON object without much luck.
The data structure is something like this:
$scope.jsonObj = {
someid8979: {
name: "Bill",
age: 18
},
someid987: {
name: "Ted",
age: 17
}
}
In my HTML, something like this:
<input ng-model="search">
<div ng-repeat="(key,val) in jsonObj | filter:search">
{{key}} - {{val.name}} - {{val.age}}
</div>
In the past, I have always sent out the data as an array of objects, and indeed, if I did that here it would work, but due to the nature of the app, this isn't possible as I need to refer to properties on the object by name (the id) elsewhere in the code.
Is there any way to apply a filter to a JSON object similar to this?
I could create a separate array just for filtering purposes and target the JSON object for my other actions, but I'd rather not :)
Edit: I made a duplicate of the object as array and looped over that, which allows filtering. This solves my problem, but not in the way I had hoped. Could be good enough.
filter
only works with arrays. – dfsq May 2 at 22:16