【问题标题】:Angular filter on object key in response响应对象键的角度过滤器
【发布时间】:2016-10-19 15:58:42
【问题描述】:

我有如下 Json 请求。我只需要过滤表中带有intrsted 的键中的值。我是过滤器和角度处理键的新手。我附上了我的 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>

【问题讨论】:

    标签: angularjs json angularjs-ng-repeat ng-repeat


    【解决方案1】:

    您的过滤器使用没有问题。问题在于您的 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>
    

    【讨论】:

    • 现在我有一个数组。如果不止一个,我该如何动态填充 item[1]?
    • 非常感谢,很有帮助
    猜你喜欢
    • 2017-03-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-03-31
    • 1970-01-01
    • 1970-01-01
    • 2017-11-14
    • 2017-01-17
    相关资源
    最近更新 更多