在Angularjs应用程序中,使用嵌套对象属性过滤ng repeat不起作用
filtering ng repeat with nested object property is not working in Angularjs application
我有以下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
过滤为
<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
,在ng个重复过滤标准中,accountsList
是基于accountNumber
和accountName
正确过滤的。但是,当我将client.name : accountSearch.clientName
包含在ng重复筛选条件中时,控制台中会显示以下错误,并且不会进行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
有人能帮忙修理吗?
使用这样的内联过滤器可以解决问题。
<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
相关文章:
- 为什么我可以在Array属性对象中找到Javascript Array for Each方法
- 使用onclick调用属性对象函数
- 嵌套为..in 循环,列出多维对象的属性(对象)
- 动态属性对象 - JSON
- 在不使用隔离范围angularjs自定义指令的情况下获取属性对象
- 通过属性传递属性/对象.Javascript
- Javascript:属性/对象的类型
- 访问JSON中的属性(对象)
- 属性对象Javascript不是用Jquery Deferred设置的
- 无法读取属性'#<对象>'未定义的获取错误
- Twitter中多属性对象的子字符串匹配
- 无法设置'data'属性'对象'标记.(只IE8)
- 更新数据属性对象属性值
- 将属性对象的选定对象从原型推入数组
- 将单个属性对象字面量的数组转换为仅包含其值的数组的最佳方法
- 寻找一种更简单的方法来检查是否多个属性&对象中的方法是未定义的
- 主干模型:带有get方法的空属性,但在属性对象中
- 如何赋值给"text"someText"属性对象在动能js
- Angularjs的数据绑定与数据属性对象
- 如何将一个嵌套的javascript对象转换为只有一级属性对象