AngularJS ng-repeat filter to child node

AngularJS ng-repeat filter to child node

本文关键字:child node to filter ng-repeat AngularJS      更新时间:2023-09-26

我有以下JSON数据结构

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

我正在尝试使用带有过滤器的 ng 重复到二级节点状态。地位。我已经尝试了以下方法,但过滤器不起作用。

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

上述情况是否可以在ng重复上实现,或者我是否需要寻找替代解决方案?

当所有其他方法都失败时,您始终可以使用自定义筛选器:

ng-repeat="d in data | myFormat"

.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;
        }
    };
});

如评论中所述

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

作品也一样