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