我有汽车过滤器具有不同的属性,你可以检查我的代码如下。AngularJS过滤器问题为不同的过滤器
<li><a ng-click="specFilter.just_arrived = ''"><h4>TODOS</h4></a></li>
<li><a ng-click="specFilter.just_arrived = true"><h4>Recently arrived</h4></a></li>
<li><a ng-click="specFilter.sale = true"><h4>sold</h4></a></li>
<li><a ng-click="specFilter.popular= true"><h4>popular</h4></a></li>
现在我的问题是,前两个<li>
工作好,因为有相同的属性just_arrived
。所以如果我选择它给我的所有或刚刚到达的汽车。但其他两个过滤器具有不同的属性:sale
和popular
。我需要或所有这四个过滤器之间的操作。
我的意思是,它应该只过滤一个属性,当前选择的前两个<li>
工作正常,但如果我选择第三或第四个过滤器,使用第一或第二个选定过滤器进行“和”操作。我需要如果我选择流行,那么唯一的结果应该是流行的汽车。如果选择出售,则需要出售汽车。如果选择最近到达的汽车,那么刚刚抵达的汽车应该只能返回。我的意思是一次只应用一个过滤器。
任何类型的帮助都是可以接受的。
角控制器
angular.module('myCarApp').controller('carController', ['$scope', '$rootScope', '$http', '$state', '$timeout', function ($scope, $rootScope, $http, $state, $timeout) {
$scope.goToItem = function (car) {
$scope.idx = $scope.cars.indexOf(car);
$state.go('car', {
info: car.year + '-' + car.brand.replace(/\s+/g, '-').toLowerCase() + '-' + car.model.replace(/\s+/g, '-').toLowerCase() + '-' + $scope.idx
});
}
$scope.specFilter = {};
function getData() {
$rootScope.showLoader = true;
//HTTP Request
$http.get('jsonurl').success(function (data) {
$scope.cars = data;
$timeout(function() {
$rootScope.showLoader = false;
}, 2000)
});
}
//PRICE SLIDER
$scope.sliderPrice = {
minValue: 0,
maxValue: 50000000,
options: {
floor: 0,
ceil: 50000000,
step: 100000,
minRange: 2000000,
maxRange: 50000000,
pushRange: true,
onChange: function() {
$(".rz-bubble").digits();
},
translate: function (value) {
return '$' + value;
}
}
};
$scope.minFilterPrice = function (car) {
return car.price_offer >= $scope.sliderPrice.minValue;
};
$scope.maxFilterPrice = function (car) {
return car.price_offer <= $scope.sliderPrice.maxValue;
};
//---------------
//KM SLIDER
$scope.sliderKm = {
minValue: 0,
maxValue: 200000,
options: {
floor: 0,
ceil: 200000,
step: 1000,
minRange: 1000,
maxRange: 200000,
pushRange: true,
onChange: function() {
$(".rz-bubble").digits();
},
translate: function (value) {
return value + ' Km';
}
}
};
$scope.minFilterKm = function (car) {
return car.km >= $scope.sliderKm.minValue;
};
$scope.maxFilterKm = function (car) {
return car.km <= $scope.sliderKm.maxValue;
};
$scope.getStyle = function (car) {
if (car.onHover) {
return {
"bottom": $(".car-overview").height() + 20
};
} else {
return {
"bottom": "0"
};
}
}
$scope.onHover = function (car) {
if ($(window).width() > 768) {
car.onHover = true;
}
}
$scope.onHoverOut = function (car) {
if ($(window).width() > 768) {
car.onHover = false;
}
}
getData();
$scope.getFormattedNumber=function(x){
return x.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ",");
};
}])
也分享你的JS代码。 – Chris
@ dhavald99您的'specFilter'用于展示合适的汽车如何? – tanmay
@tanmay specFilter.just_arrived。这意味着just_arrived是json文件中的属性,所以它会在json文件中比较just_arrived = true,并返回结果哪些cars有真正的值。它目前是过滤值,但我需要过滤一次值过滤。目前如果我过滤just_arrived,并再次如果我点击出售,那么它返回结果just_arrived &&出售。但它应该返回仅出售结果,因为上次点击已售出。 – dhavald99