Angular 在响应中过滤对象键

Angular filter on object key in response

我有 Json 请求如下。我只需要在 table.I 中使用 intrsted 过滤来自键的值,我不熟悉 angular 中的过滤器和处理键。我附上了我的 JSON 请求和回复,需要协助。

JSON:

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

Html:

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

您的过滤器使用没有任何问题。问题出在您的 ng-repeat 用法上。如果你仔细检查你的 json 对象,你会看到你的每个项目都是另一个数组,所以你需要使用内部对象作为数组。像这样修复你的 html

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

你看到你的 item 只是另一个数组,所以像 item[0] 一样使用它,你会得到你想要的结果...

更新

为了在 html 上显示内部数组列表,在第一个 ng-repeat 内部使用第二个 ng-repeat...

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