我不想顯示同一產品的兩倍。如果isbn重複,則不要將其顯示爲雙倍。從json jquery中刪除位置
{
"products": [{
"ident": "001",
"isbn": "2332",
"discount": "10%",
"bookstore": "library1"
}, {
"ident": "002",
"isbn": "2332",
"discount": "20%",
"bookstore": "library2"
}, {
"ident": "003",
"isbn": "3422",
"discount": "30%",
"bookstore": "library3"
}, ]
}
function getData() {
$.getJSON('data.json', function(data) { // get data from data.json
var products = data.products;
var tr = $("<tr>");
var items = '';
$.each(products, function(key, value) {
items += "<tr position=" + value.bookstore + ">";
items += "<td>" + value.ident + "</td>";
items += "<td>" + value.isbn + "</td>";
`enter code here`
items += "<td>" + value.discount + "</td>";
items += "<td>" + value.bookstore + "</td>";
items += "</tr>";
});
$('#data').append(items); // show data in table
});
爲什麼你的問題描述有太多重複? – GibboK
不錯的口頭禪!知道哪個被保存或丟棄的規則是什麼?第一個? – Kaddath
我多次重複添加錯誤。對不起 – Piotr