那位大佬有更好的方法 可以发出来看看
//异步请求
let getLabel = () => {
return new Promise(resolve => {
let list = this.applicableJson.brandList;//获取总数据
let arry = [];
for (let i = 0; i < list.length; i++) {
for (let j = 0; j < list[i].child.length; j++) {
for (let k = 0; k < row.disabled_data.length; k++) {
if (list[i].child[j].recovery_cat_id == row.disabled_data[k]) {//判断id相同
arry.push({//合并生成新数组
name: list[i].cat_name,
child: [list[i].child[j].cat_name]
});
}
}
}
}
resolve(arry);
});
};
getLabel().then(res => {
let arr = [];
for (let i = 0; i < res.length; i++) {
if (i < res.length - 1 && res[i].name == res[i + 1].name) {//判断相同的数据合并
arr.push(res[i].child[0]);
} else {
arr.push(res[i].child[0]);
this.applicableJson.brandTable.push({
name: res[i].name,
child: arr
});
arr = [];//清空
}
}
});