给定一个具有 $scope 属性的控制器,它是一个具有其他属性的对象,而不是像下面这样的数组,我应该如何过滤ng-repeat
集合?
这是一个 JSFiddle:http: //jsfiddle.net/ZfGx4/110/
控制器:
function HelloCntl($scope, $filter) {
$scope.friends = {
john: {
name: 'John',
phone: '555-1276'
},
mary: {
name: 'Mary',
phone: '800-BIG-MARY'
},
mike: {
name: 'Mike',
phone: '555-4321'
},
adam: {
name: 'Adam',
phone: '555-5678'
},
julie: {
name: 'Julie',
phone: '555-8765'
}
};
}
模板:
<div ng:app>
<div ng-controller="HelloCntl">
<input placeholder="Type to filter" ng-model="query">
<ul>
<li ng-repeat="(id, friend) in friends | filter:query">
<span>{{friend.name}} @ {{friend.phone}}</span>
</li>
</ul>
</div>
</div>