简体   繁体   English

AngularJS ng-repeat过滤到子节点

[英]AngularJS ng-repeat filter to child node

I have the following JSON data structure 我有以下JSON数据结构

{ "firstName" : "John",
  "role" : "Manager",
  "status" : {
                "Id" : 30,
                "Status" : "Appointment booked",
                "statusDate" : 1467826508775
             },
  "surname" : "Smith",
  "title" : "Mr",
}

and I am trying to use an ng-repeat with a filter to the second level node status.Status. 我试图使用带有过滤器的ng-repeat到第二级节点status.Status。 I have tried the following but the filter does not work. 我尝试了以下但过滤器不起作用。

ng-repeat="data in data | filter: {status.Status: 'Appointment booked'}"

Is the above possible on ng-repeat or do I need to look at an alternative solution? 以上是否可以在ng-repeat上进行,还是需要查看替代解决方案?

You can always use a custom filter when all else fails: 当其他所有方法都失败时,您始终可以使用自定义筛选

ng-repeat="d in data | myFormat"

JS: JS:

app.controller('myCtrl', function ($scope) {
    $scope.data = {
        "firstName": "John",
        "role": "Manager",
        "status": {
            "Id": 30,
            "Status": "Appointment booked",
            "statusDate": 1467826508775
        },
        "surname": "Smith",
        "title": "Mr",
    }
});

app.filter('myFormat', function () {
    return function (x) {
        if (x.status.Status == 'Appointment booked') {
            return x;
        }
    };
});

As mentionned in comments 正如评论中提到的那样

ng-repeat="d in data | filter : {status: { Status : 'Apointment booked'}}"

works aswell 也起作用

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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