如何通过嵌套对象的属性过滤ng-repeat

时间:2014-11-20 14:22:13

标签: angularjs filter ng-repeat

我有以下数组:

  var boofers = [
    {
        "id" : "kurfki8z6786",
        "query" : {"name": "foo", "status": "open"},
        "uid" : "1416422209395",
    },
    {
        "id" : "kurfki8z6874",
        "query" : {"name": "puff", "status": "closed"},
        "uid" : "1416422209387",
    },
    {
        "id" : "kurfki8z6123",
        "query" : {"name": "joe", "status": "closed"},
        "uid" : "1416422209301",
    }
  ]

我需要在uid个对象的boofers查询status boofer的{​​{1}}值打印为closed,所以我正在尝试以下内容但是没有得到结果,因为{{boofer.uid}}没有打印出来:

<div ng-repeat="boofer in boofers | filter: {query.status: 'closed'}">{{boofer.uid}}</div>

有人可以告诉我我在这里犯的错误以及如何解决它?

2 个答案:

答案 0 :(得分:1)

从JSON数组中的每个)中删除id

boofers = [
    {
        "id" : "kurfki8z6786",
        "query" : {"name": "foo", "status": "open"},
        "uid" : "1416422209395",
    },
    {
        "id" : "kurfki8z6874",
        "query" : {"name": "puff", "status": "closed"},
        "uid" : "1416422209387",
    },
    {
        "id" : "kurfki8z6123",
        "query" : {"name": "joe", "status": "closed"},
        "uid" : "1416422209301",
    }
  ];

这里: http://jsfiddle.net/nk5Loxoy/

注意:如果您在编辑之前在查询中使用数组,则应使用自定义过滤器

答案 1 :(得分:0)

您可以使用ng-if?

<div ng-repeat="boofer in boofers" ng-if="boofer.query.status==='closed'">{{boofer.uid}}</div>