简体   繁体   中英

How to make custom filter for a only json objects keys not for values in angularjs

I am new to angularjs and was trying to filter nested json data basically what i am trying to do is trying to make a custom filter for only json objects keys not for values. i want to show all the keys with value that i will place in a search field.

It is much better idea to iterate through the array instead of object. Transform your object into array and then simply print the values what do you need using the filter:

JavaScript

[...]

var arr = [];
for (var i in obj) {
   if (obj.hasOwnProperty(i)) {
      arr.push(obj[i]);
   }
}

[...]

HTML

[...]

<div>
   <input type="text" ng-model="search.a" />
</div>

<div ng-repeat="item in arr | filter:search">
   {{item.a}}
   {{item.b}}
   {{item.c}}
</div>

[...]

EDIT

Related to the picture you posted you need something like this.

HTML

[...]

<div>
   <input type="text" ng-model="search.id" />
</div>

<div ng-repeat="item in items | filter:search">
   {{item.index}}
   {{item.id}}
</div>

[...]

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM