javascript - 使用嵌套对象属性过滤 ng 重复在 Angularjs 应用程序中不起作用

标签 javascript angularjs angularjs-directive angularjs-ng-repeat

我有以下 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}">

在我的 Controller 中我有:

 $scope.accountSearch = {
                accountNumber :'',
                accountName : '',
                clientName : ''
        };

如果我删除 client.name : accountSearch.clientName,在 ng repeat 过滤条件中,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

谁能帮忙解决一下?

最佳答案

像这样使用您的内联过滤器可以解决问题。

<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

关于javascript - 使用嵌套对象属性过滤 ng 重复在 Angularjs 应用程序中不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34119870/

相关文章:

javascript - 这个css代表什么?

javascript - 将变量从按钮传递到模态

javascript - 将 jsonarray 分割成 block 数组到另一个数组中

javascript - AngularJS 中单选按钮的奇怪行为

javascript - AngularJS 中传递给指令的属性仅更改为指令范围,但不会更改为外部

javascript - 使用 JavaScript 显示一个 div

javascript - 使用 Javascript 将参数从 URL 传递到隐藏表单字段 (Gridview)

javascript - 在nodejs中使用writeFile时未创建文件

php - Angular 和 MySQL - 前端过滤与多个查询

AngularJS:为什么以及何时需要调用 $timeout?