Nicoleta Wilskon
Nicoleta Wilskon

Reputation: 697

Angular filter on object key in response

I have Json request as below. I need to filter only values from key with intrsted in table.I am new to filters and handling key in angular. I attached my JSON request and response, need assistane.

JSON:

var customer = 
 [
  [
    {
      "businessuserid": 44,
      "businessusername": "rk business New",
      "businessusermobile": "00",
      "businessusercountrycode": "91",
      "admin": true,
      "mobilevalidated": false,
      "emailvalidated": false,
      "email": "[email protected]",
      "upin": "000044"
    }
  ],
  [
    {
      "approved": true,
      "businessuserid": 43,
      "businessusername": "Cakey Bakes",
      "businessusermobile": "8050663763",
      "businessusercountrycode": "91",
      "admin": true,
      "mobilevalidated": true,
      "emailvalidated": false,
      "email": "[email protected]",
      "upin": "000043"
    }
  ],
  [
    {
      "intrsted": true,
      "attended": false,
      "businessuserid": 44,
      "businessusername": "rk business New",
      "businessusermobile": "00",
      "businessusercountrycode": "91",
      "admin": true,
      "mobilevalidated": false,
      "emailvalidated": false,
      "email": "[email protected]",
      "upin": "000044"
    }
  ],
  [
    {
      "intrsted": true,
      "attended": false,
      "businessuserid": 52,
      "businessusername": "Cars workshop",
      "businessusermobile": "9535000636",
      "businessusercountrycode": "91",
      "admin": true,
      "mobilevalidated": true,
      "emailvalidated": false,
      "email": "[email protected]",
      "upin": "000052"
    }
  ]

Html:

 <table ng-repeat="item in customers | filter: { intrsted: true }">
    <td>{{item.businessusername}}</td>
    <tr>
</table>

Upvotes: 0

Views: 364

Answers (1)

Poyraz Yilmaz
Poyraz Yilmaz

Reputation: 5857

There is nothing wrong with your filter usage. Problem is at your ng-repeat usage. If you double check your json object you will see your every item is another array so you need to use inner object as array. Fix your html like this

<table ng-repeat="item in customers | filter: { intrsted: true }">
    <td>{{item[0].businessusername}}</td>
</table>

You see your item is just an another array so use it like item[0] and you will get the result you want...

UPDATE

for showing inner array list on html use second ng-repeat inside of first ng-repeat...

<table ng-repeat="item in customers | filter: { intrsted: true }">
    <td ng-repeat="customer in item">{{customer.businessusername}}</td>
</table>

Upvotes: 1

Related Questions