Having Issues In Filtering With Product List With Data Attributes
Andrew
).change(function(){
if($(this).is(":checked")){
$('#prod >div').hide();
if(this.className == "brand"){
console.debug("brand checked");
brand.push($(this).attr('id'));
}elseif(this.className == "store"){
console.debug("store checked");
store.push($(this).attr('id'));
}
console.log(brand+","+store);
displaydivs(brand,store);
}else{
$('#prod >div').show();
if(this.className == "brand"){
var index = brand.indexOf($(this).attr('id'));
if (index > -1) {
brand.splice(index, 1);
}
}elseif(this.className == "store"){
var index = store.indexOf($(this).attr('id'));
if (index > -1) {
store.splice(index, 1);
}
}
displaydivs(brand,store);
}
});
functiondisplaydivs(brand,store)
{
$("#prod >div").hide();
if(brand.length > 0 & store.length > 0){
$.each(brand, function( index, value ){
var temp = $("#prod >div[data-brand="+value+"]")[0];
var data = $(temp).attr("data-store");
var idx = store.indexOf(data);
if(idx > -1){
$("#prod >div[data-brand="+value+"][data-store="+data+"]").show();
}
});
$.each(store, function( index, value ){
var temp = $("#prod >div[data-store="+value+"]")[0];
var data = $(temp).attr("data-brand");
var idx = brand.indexOf(data);
if(idx > -1){
$("#prod >div[data-brand="+data+"][data-store="+value+"]").show();
}
});
}
elseif(brand.length > 0 & !(store.length > 0)){
$.each( brand, function( index, value ){
$("#prod >div[data-brand="+value+"]").show();
});
}
elseif(!(brand.length > 0) & store.length > 0){
$.each( store, function( index, value ){
$("#prod >div[data-store="+value+"]").show();
});
}else{
$("#prod >div").show();
}
}
Demo : http://jsfiddle.net/qxxL2/4/
Post a Comment for "Having Issues In Filtering With Product List With Data Attributes"