給定一個具有$ scope屬性的控制器,該屬性是具有其他屬性而不是像下面這樣的數組的對象,應如何過濾ng-repeat
集?在AngularJS上的對象映射而不是陣列上過濾
這裏是一個的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>
的jsfiddle不再起作用 – Jackie