I tried many different methods but can't seem to work this one out. I have a JSon array which populates my JQuery list. The list displays correctly, but I cant seem to be able to filter it.
I'd like to be able to filter by name or price. I tried the JQuery .Filter method and many others, and they all failed. I'd also like to make it as a link. ( The user clicks sort by name, and it sorts... )
Heres what I have so far, which I was convinced would work.
Any help is greatly appreciated, Thanks !
.js file :
// Json array
var productList = {"products": [
{"description": "Product 1", "price": "3.25"},
{"description": "Product 4", "price": "9.97"},
{"description": "Product 3", "price": "4.21"},
{"description": "Product 2", "price": "5.24"},
{"description": "Product 5", "price": "8.52"}
]
};
function loadList() {
var list = $("#productList").listview();
// load array into list
$(productList.products).each(function(index) {
$(list).append('<li id="listitem">' + this.description + " " +
" : " + this.price + '</li>');
// sort by price
$(productList.products).filter(function ()
{ return parseFloat(this.price) < 11;})
});
$(list).listview("refresh");
}