【发布时间】:2011-08-16 21:31:15
【问题描述】:
我目前有一些代码可以使用滑块根据价格范围过滤数组。我需要能够为各种尺寸和颜色添加复选框,以便我还可以使用它们的值进行过滤。这是我到目前为止的代码,但不确定如何实现复选框,以便我有多种过滤数组的方法。
//this is the main generated array
var product = [{"price":"200","color":"red","size":"small"},
{"price":"250","color":"brown","size":"medium"},
{"price":"300","color":"red","size":"large"}];
// array to display filtered array
var filteredProducts = [];
var key = 0;
//start of price range filter
if(!minPrice && !maxPrice){
filteredProducts = products;
} else{
$.each(products, function(i, object) {
var curentPrice = parseFloat(object.price);
var priceMinOk = true;
var priceMaxOk = true;
// filter results match the price range
if(maxPrice || minPrice){
if(maxPrice && maxPrice<curentPrice){
priceMaxOk = false;
}
if(minPrice && minPrice>curentPrice){
priceMinOk = false;
}
}
// loop over list and get only related to new array
if( priceMinOk && priceMaxOk ){
filteredProducts[key] = object;
key++;
}
});
}
提前感谢您的帮助”
【问题讨论】: