我有这个代码块,将我的数组中的"类别"显示为一个JQuery简单列表.
它工作正常,但如果"篮球"类别中有3个项目,该类别将出现3次.
我怎么能这样才能出现一次呢?谢谢.
这是代码:
function loadCategories() {
console.debug('About to refresh with sort type : ' + sortType);
var items = [];
$.each(catalog.products,
function(index, value) {
items.push('<li id="' + index + '">' +
'<a data-identity="productId" href="./productList.page?category=' + value.category + '" >' +
'<p style="margin-bottom:0px;margin-top:0px;">' + value.category + '</p></a> </li>');
}
);
categoryView.html(items.join(''));
categoryView.listview('refresh');
}
Run Code Online (Sandbox Code Playgroud)
这是我的数组的代码:
var catalog = {"products": [
{"id": "10001",
"name": "Mountain bike",
"color": "Grey/Black",
"long-desc": "12-speed, carbon mountain bike.",
"description": "",
"size": "20 inches",
"category": "Outdoors/ Equipment rental", …Run Code Online (Sandbox Code Playgroud)