我有一个与此类似的对象:
$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'}}"
。在这里,我应该得到第一份合同,但我有一个空数组。
答案 0 :(得分:3)
其错误partner
在过滤器中应为partners
。
ng-repeat="contract in contracts | filter : {partners: {name: 'John'}}"