效果:需要考慮擴展性,比如後面增加一條訂單爲003餓下面的tab也要增加一個003
001 002 根據上面的數據展示訂單號 這是一個tab
對應的訂單數據 比如001 有2條數據 這裏就展示2條數據
數據:
const dataList = [
{
"orderId":"001",
"name":"書",
"intro":"書的簡介"
},
{
"orderId":"002",
"name":"筆",
"intro":"筆的簡介"
},
{
"orderId":"003",
"name":"電腦",
"intro":"電腦的簡介"
},
{
"orderId":"001",
"name":"書桌",
"intro":"書桌的簡介"
}
const pjson = {};
const birthdayList = this.dataList;
for (let i = 0; i < birthdayList.length; i++) {
if (pjson.hasOwnProperty(birthdayList[i].orderId)) {
pjson[birthdayList[i].orderId ].push(birthdayList[i]);
}
else {
//如果不存在
var v = [];
v.push(birthdayList[i]);
pjson[birthdayList[i].orderId] = v;
}
}
console.log(pjson)