У меня есть этот блок кода, который отображает «категории» из моего массива в простой список 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');
}
Вот код моего массива:
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",
"sport": "Cycling",
"brand": "DaVinci",
"top-seller": ""},
{"id": "10002",
"name": "Pro Multi Basketball",
"color": "Rainbow",
"long-desc": "On sale this week only! This limited edition basketball is multi-coloured, and offers pro performance. Fun and games on the court!",
"description": "Limited edition basketball.",
"size": "N/A",
"category": "Team gear",
"sport": "Basketball",
"brand": "Nike",
"top-seller": "x"},