这是使用ng-repeat
自定义过滤器执行此操作的方法。只需使用您的绑定值并将它们替换为min
和max
类似myfilter
:
<div ng-repeat="item in items | myfilter: { min: slider.min, max: slider.max }">
JSFiddle
HTML:
<div ng-app="app" ng-controller="dummy">
<div ng-repeat="item in items | myfilter: { min: 185, max: 500 }">
<p>{{item.name}}</p>
</div>
</div>
JS:
var app = angular.module("app", []);
app.controller('dummy', function($scope, $sce) {
$scope.items = [{name: 'hello', cost: 100}, {name: 'world', cost: 200}]
});
app.filter('myfilter', function() {
return function( items, condition) {
var filtered = [];
if(condition === undefined || condition === ''){
return items;
}
angular.forEach(items, function(item) {
if(item.cost >= condition.min && item.cost <= condition.max){
filtered.push(item);
}
});
return filtered;
};
});