我有以下json
,
$scope.accountsList = [ {
"id": 1,
"number": "AFRC1234",
"name": "ACFRYTE431",
"postalCode": "76565",
"invoices": null,
"courier": {
"id": 1,
"name": "UPS"
},
"client": {
"id": 1,
"code": "FREG",
"name": "Feranget"
}
} ]
我正在过滤ng-repeat
as,
<tr ng-repeat="account in accountsList | filter:{ number: accountSearch.accountNumber, name: accountSearch.accountName, client.name : accountSearch.clientName}">
在我的控制器中,我有:
$scope.accountSearch = {
accountNumber :'',
accountName : '',
clientName : ''
};
如果我删除client.name : accountSearch.clientName
,则在重复过滤条件中,accountsList
已根据accountNumber
和accountName
正确过滤。但是当我在ng重复过滤条件中包含client.name : accountSearch.clientName
时,控制台中会显示以下错误,并且不会对accountsList
进行过滤。
Error: [$parse:syntax] Syntax Error: Token '.' is unexpected, expecting [:] at column 66 of the expression [accounts | filter:{ number: accountSearch.accountNumber, client.name : accountSearch.clientName }] starting at [.name : accountSearch.clientName }].
http://errors.angularjs.org/1.4.3/$parse/syntax?p0=.&p1=is%20unexpected%2C%20expecting%20%5B%3A%5D&p2=66&p3=accounts%20%7C%20filter%3A%7B%20number%3A%20accountSearch.accountNumber%2C%20%20%20client.name%20%3A%20accountSearch.clientName%20%7D&p4=.name%20%3A%20accountSearch.clientName%20%7D
minErr/<@http://localhost:8080/bower_components/angular/angular.js:68:12
AST.prototype.throwError@http://localhost:8080/bower_components/angular/angular.js:12881:1
AST.prototype.consume@http://localhost:8080/bower_components/angular/angular.js:12893:1
AST.prototype.object@http://localhost:8080/bower_components/angular/angular.js:12870:9
任何人都可以帮忙解决问题吗?
答案 0 :(得分:1)
使用类似的内联过滤器解决问题。
<div ng-repeat="account in accountsList | filter:{ number: accountSearch.accountNumber, name: accountSearch.accountName, client :{ name: accountSearch.clientName} }">
这是工作的plnkr检查这个。http://plnkr.co/edit/B3R758UjxldvZLDkxO8E?p=preview