【发布时间】:2011-09-26 05:04:21
【问题描述】:
我有一个功能,可以在页面加载时按价格过滤列表中的项目。我想将此附加到一个链接上,而不是在页面加载时对列表进行排序,我想让用户单击一个链接或按钮来按价格过滤列表。
任何有关如何执行此操作的线索或指示都会很棒,谢谢!
// Json array
var productList = {"products": [
{"brand": "brand1", "description": "Product 1", "price": "3.25"},
{"brand": "brand2", "description": "Product 4", "price": "9.97"},
{"brand": "brand3", "description": "Product 3", "price": "4.21"},
{"brand": "brand4", "description": "Product 2", "price": "5.24"},
{"brand": "brand5", "description": "Product 5", "price": "8.52"}
]
};
// SORT BY DESCRIPTION ASCENDING
function loadList() {
var list = $("#productList").listview();
var prods = productList.products.sort(function (a, b) {
return a.description > b.description;
});
$.each(prods, function () {
list.append("<li>" + this.description + " : " + this.price + "</li>");
});
$(list).listview("refresh");
}
【问题讨论】:
标签: jquery arrays json filter sorting