1
我正在嘗試使用複選框值來過濾結果。我需要能夠按評分過濾。這是我到目前爲止的代碼:創建角度過濾器功能的問題
<label ng-repeat="rating in ratings">
<input type="checkbox" value="{{rating.value}}" ng-model="rating.selected" ng-change="ratingFilter(hotel, rating)" ng-init="ratingFilter(hotel, rating, 'init')">
{{rating.name}}
</label>
$scope.ratings = [
{ name:'One Star', value:1, selected: true},
{ name:'Two Stars', value:2, selected: true},
{ name:'Three Stars', value:3, selected: true},
{ name:'Four Stars', value:4, selected: true},
{ name:'Five Stars', value:5, selected: true}
]
<div ng-repeat="hotel in (filteredHotels = (hotelResults | filter: resortFilter | filter: bbFilter | filter: priceFilter | filter: ratingFilter)) | startFrom:(currentPage - 1)*10 | limitTo:10 " class="hotel-results-container">
我需要一個ratingFilter
功能,這樣的事情:
$scope.ratingFilter = function (hotel, rating, init) {
return (hotel.Rating >= $scope.hotelResults.Rating);
}
這不工作,雖然。
我創建了一個priceFilter
功能和工作原理:
$scope.priceFilter = function (hotel) {
return (hotel.Price > $scope.hotelResults.minPrice && hotel.Price < $scope.hotelResults.maxPrice);
}
誰能幫我篩選通過評價的結果?
您可以同時使用'hotelResults'作爲collection(ng-repeat)和object('scope.hotelResults.minPrice')。它是什麼? – mrak 2014-12-04 12:26:51
也許這是問題的一部分。看起來這些數據結構基本相同。我想要做的就是如果複選框被選中,則返回其中具有複選框值的數據。我今天嘗試了很多東西,我可能不完全理解這一點來解決它。對不起,我迷路了:( – user1532669 2014-12-04 17:47:10
這可能有所幫助:http://jsfiddle.net/ExpertSystem/wYfs4/3/ – user1532669 2014-12-04 22:35:40