Angularjs基于Array类型的属性过滤数组

时间:2016-10-29 17:26:33

标签: javascript angularjs

我有一个与此类似的对象:

$scope.contracts = [
 {
  name: "contract1",
  partners : [{name: "John", age:"21"}, {name: "Peter", age: "33"}]
 },
 {
  name: "contract2",
  partners : [{name: "George", age:"51"}, {name: "Jack", age: "42"}]
 }
];

如何根据HTML中合作伙伴的名称过滤$scope.contracts? 例如ng-repeat="contract in contracts | filter : {partner: {name: 'John'}}"。在这里,我应该得到第一份合同,但我有一个空数组。

1 个答案:

答案 0 :(得分:3)

其错误partner在过滤器中应为partners

ng-repeat="contract in contracts | filter : {partners: {name: 'John'}}"