var filtered_value = $(this).attr("filterset");
var filter_attribute = $(this).parent().parent().attr('data-facet');
var count = 0;
var filtered_json = [];
$.getJSON('<?php echo $jsonFileUrl;?>', function (json) {
for (var i = 0; i < json.length; i++) {
if(json[i][filter_attribute] == filtered_value){
count++;
filtered_json.push(json[i]);
}
}
//console.log(filtered_json);
var filterList = $.parseJSON(filtered_json);
console.log(filterList);return false;
var html = '';
for (x in filterList) {
html += '<li>' + filterList[x].name
}
});
I have this code in my product listing page. And I am getting products from json file. Now I want to filter this products based on size, color,price.
How can I use filtered json data for building li ?
I am getting null value in console?:(
2
Answers
This will work :
Javascript version —
jQuery version —