我有以下
JSON数据结构
{ "firstName" : "John",
"role" : "Manager",
"status" : {
"Id" : 30,
"Status" : "Appointment booked",
"statusDate" : 1467826508775
},
"surname" : "Smith",
"title" : "Mr",
}
我试图使用带有过滤器的ng-repeat到第二级节点status.Status.我尝试了以下但过滤器不起作用.
ng-repeat="data in data | filter: {status.Status: 'Appointment booked'}"
以上是否可以在ng-repeat上进行,还是需要查看替代解决方案?
最佳答案 当其他所有方法都失败时,您始终可以使用自定义筛选
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'}}"
也起作用