js操作两个一维数组转换为二维数组
forEach 和 filter结合使用
a.forEach((item,index)=>{
item.children = b.filter(items=>{
return items.goodsCategory === item.id;
})
})
console.log(a);
let a = [
{
cagegoryName: "感冒药",
createTime: "2020-06-19 14:44:51",
delFlag: 1,
id: "1273869332852719616",
industryCategory: 2,
level: 1,
merchantId: "1239217264236613632",
merchantUserId: "1273867462012780544",
name: null,
parentId: "0",
sort: 1,
storeId: "1273867968638566400",
updateTime: "2020-06-19 14:44:51",
},
{
cagegoryName: "消炎药",
createTime: "2020-06-19 14:45:02",
delFlag: 1,
id: "1273869379375939584",
industryCategory: 2,
level: 1,
merchantId: "1239217264236613632",
merchantUserId: "1273867462012780544",
name: null,
parentId: "0",
sort: 1,
storeId: "1273867968638566400",
updateTime: "2020-06-19 14:45:02",
},
];
let b = [
{
createTime: "2020-06-19 14:48:57",
delFlag: 1,
goodsCategory: "1273869332852719616",
goodsCode: "123456",
goodsName: "感冒灵颗粒",
goodsPic