問題:
I am trying to filter the list with multiple filters + with a custom filter function. 我試圖使用多個過濾器+使用自定義過濾器功能過濾列表。
The original working jsfiddle example is http://jsfiddle.net/ed9A2/1/ but now I want to change the way age are being filter. 最初的工作jsfiddle示例是http://jsfiddle.net/ed9A2/1/,但現在我想改變年齡過濾方式。
I want to add a custom filter so that age it filter based on two input value which is min_age and max_age , (between age) . 我想添加自定義過濾器,以便年齡段正是過濾器的基礎上這是MIN_AGE和MAX_AGE,(年齡之間)兩個輸入值。
After looking into doc. 在研究了doc之後。 I found people having similar questions and a user Mark Rajcok answer http://docs.angularjs.org/api/ng.filter:filter#comment-648569667 looks good and should be working. 我發現人們有類似的問題和用戶Mark Rajcok回答http://docs.angularjs.org/api/ng.filter:filter#comment-648569667看起來不錯,應該可以正常工作。 But I am having problem applying it into my codes which mainly seems to because I have other multiple filters. 但我有問題將其應用到我的代碼中,這主要是因爲我有其他多個過濾器。
Im very new to AngularJS :( 我對AngularJS很新:(
My tried and NOT working fiddle is here http://jsfiddle.net/ed9A2/20/ 我試過而且不工作的小提琴就在這裏http://jsfiddle.net/ed9A2/20/
A copy paste of my NOT working codes are here 我的NOT工作代碼的複製粘貼在這裏
View 視圖
<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>
Controller 調節器
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}
]
}