AngularJS多重filter具有自定义过滤function

我正在尝试使用多个filter+自定义filter函数来过滤列表。

原来的工作jsfiddle的例子是http://jsfiddle.net/ed9A2/1/,但现在我想改变年龄正在过滤的方式。

我想添加一个自定义filter,以便根据两个input值min_agemax_age (年龄之间)进行过滤。

看了doc后。 我发现有人有类似的问题和用户马克Rajcok回答http://docs.angularjs.org/api/ng.filter:filter#comment-648569667看起来不错,应该工作。 但我有问题应用到我的代码主要似乎是因为我有其他多个filter。

我很新AngularJS 🙁

我尝试过,不工作的小提琴在这里http://jsfiddle.net/ed9A2/20/

我的NOT工作代码的复制粘贴在这里

视图

<div ng-app ng-controller="MainController"> <table class="fancyTable"> <tr> <th>Player id</th> <th>Player name</th> <th>Age</th> </tr> <tr> <td><input ng-model="player_id" /></td> <td><input ng-model="player_name" /></td> <td> Min Age:<input ng-model="min_age" /> Max Age:<input ng-model="max_age" /> </td> </tr> <tr ng-repeat="player in players | filter:{id: player_id, name:player_name, age:ageFilter}"> <td>{{player.id}}</td> <td>{{player.name}}</td> <td>{{player.age}}</td> </tr> </table> 

调节器

 function MainController($scope) { $scope.player_id = ""; $scope.player_name = ""; $scope.player_age = ""; $scope.min_age = 0; $scope.max_age = 999999999; $scope.ageFilter = function(player) { return ( player > $scope.min_age && player.age < $scope.max_age); } $scope.players = [ {"name": "Rod Laver", "id": "rod", "date": "1938/8/9", "imageUrl": "img/rod-laver.gif", "age": 75}, {"name": "Boris Becker", "id": "borix", "date": "1967/11/22", "imageUrl": "img/boris-becker.gif", "age": 45}, {"name": "John McEnroe", "id": "mcenroe", "date": "1959/2/16", "imageUrl": "img/john-mc-enroe.gif", "age": 54}, {"name": "Rafa Nadal", "id": "nadal", "date": "1986/5/24", "imageUrl": "img/ndl.jpg", "age": 27} ] } 

尝试这个:

 <tr ng-repeat="player in players | filter:{id: player_id, name:player_name} | filter:ageFilter"> $scope.ageFilter = function (player) { return (player.age > $scope.min_age && player.age < $scope.max_age); } 

希望下面的答案在这个链接将有助于, 多值filter

并用例子来看看小提琴

 arrayOfObjectswithKeys | filterMultiple:{key1:['value1','value2','value3',...etc],key2:'value4',key3:[value5,value6,...etc]} 

小提琴