[英]How to filter data in ng-repeat using a jquery slider?
I am using Ion.RangeSlider that is a jquery slider. 我使用的是一个jquery滑块Ion.RangeSlider 。 I have json data that is coming through http and i am displaying it in the page using ng-repeat directive. 我有通过http发送的json数据,我使用ng-repeat指令在页面中显示它。 I want to filter the JSON data using this slider that looks like below 我想使用下面的滑块过滤JSON数据
under the image you can see two values 185;500 that is the value i am getting when i bind ng-model to the slider. 在图像下你可以看到两个值185; 500 ,这是我将ng-model绑定到滑块时得到的值。
so, my questions is how do i filter my data using this slider ? 所以,我的问题是如何使用此滑块过滤我的数据?
EDIT I changed the Slider that i was using and made the same CSS changes to make it look like the above slider. 编辑我改变了我正在使用的Slider并进行了相同的CSS更改,使其看起来像上面的滑块。 https://github.com/rzajac/angularjs-slider https://github.com/rzajac/angularjs-slider
Here is how you can do that with ng-repeat
and a custom filter. 以下是使用ng-repeat
和自定义过滤器的方法。 Just use your binded value and replace them as min
and max
in myfilter
like: 只需使用您的绑定值并将其替换为myfilter
min
和max
,如:
<div ng-repeat="item in items | myfilter: { min: slider.min, max: slider.max }">
HTML: 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: 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;
};
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.