Angularjs 范围滑块角度js上的过滤器ng重复
我正在我的项目中使用rangle slider。我想过滤范围滑块滑动时的ng重复。我想过滤价格数据。我的代码 html:-Angularjs 范围滑块角度js上的过滤器ng重复,angularjs,filter,rangeslider,Angularjs,Filter,Rangeslider,我正在我的项目中使用rangle slider。我想过滤范围滑块滑动时的ng重复。我想过滤价格数据。我的代码 html:- 属性:{{data.name} 价格:{{data.price} 控制器:- $scope.data = [{ name : hoarding1, price : 50000 }, { name :
属性:{{data.name}
价格:{{data.price}
控制器:-
$scope.data = [{
name : hoarding1,
price : 50000
},
{
name : hoarding2,
price : 50000
},
{
name : hoarding3,
price : 50000
}
]
$scope.slider = {
step : 10000,
min : Math.min.apply(Math,$scope.data.map(function(item){return item.price;})),
max : Math.max.apply(Math,$scope.data.map(function(item){return item.price;}))
}
$scope.rangeSlider = function (){
return function( items, rangeInfo ) {
var filtered = [];
var min = parseInt(rangeInfo.min);
var max = parseInt(rangeInfo.max);
// If time is with the range
angular.forEach(items, function(item) {
if( item.price >= min && item.price <= max ) {
filtered.push(item);
}
});
return filtered;
};
$scope.data=[{
名称:囤积1,
价格:50000
},
{
名称:囤积2,
价格:50000
},
{
名称:囤积3,
价格:50000
}
]
$scope.slider={
步骤:10000,
min:Math.min.apply(Math$scope.data.map(函数(项){return item.price;})),
max:Math.max.apply(Math$scope.data.map(函数(项){returnitem.price;}))
}
$scope.RangeSlaider=函数(){
返回函数(项目、范围信息){
var筛选=[];
var min=parseInt(rangeInfo.min);
var max=parseInt(rangeInfo.max);
//如果时间在范围内
角度。forEach(项目、功能(项目){
如果(item.price>=min&&item.price如果要实现自定义过滤器,则应在此处检查信息
创建自定义过滤器后,应按如下方式使用:
<div ng-repeat="data in data | customFilterName">
注意:我建议您不要对每个数据实例使用名称,例如data
。可能更好的方法是“数据中的项目”
或类似的smth。我想您需要一个自定义过滤器,用于过滤特定的价格,并显示价格上具有过滤边界的特定项目,请参阅be低代码
控制器:
$scope.rangeInfo = {
min : Math.min.apply(Math,$scope.data.map(function(item){return item.price;})),
max : Math.max.apply(Math,$scope.data.map(function(item){return item.price;}))
}
模板:
<div ng-repeat="data in data | priceRange:rangeInfo">
Property: {{data.name}}
price: {{data.price}}
</div>
属性:{{data.name}
价格:{{data.price}
过滤器
您可以使用forEach数组方法或数组的filter方法(ES5)
app.filter('priceRange',function(){
返回函数(arrayItems、rangeInfo){
返回arrayItems.filter(函数(项){
控制台日志(项目价格);
返回(item.price>rangeInfo.min和&item.price
使用箭头函数的ES2015(ES6)过滤方法
app.filter('priceRange',function(){
return function(arrayItems,rangeInfo){
return arrayItems.filter((item) => (item.price > rangeInfo.min && item.price < rangeInfo.max));
}
});
app.filter('priceRange',function(){
返回函数(arrayItems、rangeInfo){
返回arrayItems.filter((item)=>(item.price>rangeInfo.min&&item.price
很抱歉,这不是资产,这是我提供的数据@Vlad Dekhanov你能分享你的rangeFilter
对象的内容吗?请详细说明,你想过滤只有价格的对象吗?什么是rangeFilter$scope.RangeSlaider=function(){return function(items,rangeInfo){var filtered=[];var min=parseInt(rangeInfo.min);var max=parseInt(rangeInfo.max);//如果时间在angular.forEach范围内(项目,函数(项目){If(item.price>=min&&item.price很抱歉,但是您的示例没有解释什么是rangeFilter
@Ranjith,当然!没问题。我很高兴它对您有用。
app.filter('priceRange',function(){
return function(arrayItems,rangeInfo){
return arrayItems.filter(function(item){
console.log(item.price);
return (item.price > rangeInfo.min && item.price < rangeInfo.max);
});
}
});
app.filter('priceRange',function(){
return function(arrayItems,rangeInfo){
return arrayItems.filter((item) => (item.price > rangeInfo.min && item.price < rangeInfo.max));
}
});