mysql 表里这种构造
咱们理论想要的是树型构造
间接上代码
buildMenuTree: function (arr, res = []) {for (let i = 0; i < arr.length; i++) {if(arr[i].type === '0') {arr[i].children = []
for (let j = 0; j < arr.length; j++) {if (arr[i].id === +arr[j].parentId) {arr[i]['children'].push(arr[j])
}
}
if(arr[i].children.length>0) {res.push(arr[i])
}else {delete arr[i].children
res.push(arr[i])
}
}
}
return res
}
欢送点赞 + 评论 + 转发, 蜗牛老湿作