treeDate(list) {
let treeList = [];
let treeMap = {};
for (let i = 0; i < list.length; i++) {
list[i]["id"] = list[i]["quesId"];
delete list[i]["quesId"];
/* list[i]["name"] = list[i]["name"]; delete list[i]["name"];*/
treeMap[list[i]["id"]] = list[i];
}
for (var i = 0; i < list.length; i++) {
if (treeMap[list[i]["parentId"]] && list[i]["id"] != list[i]["parentId"]) {
if (!treeMap[list[i]["parentId"]]["children"]) {
treeMap[list[i]["parentId"]]["children"] = [];
}
treeMap[list[i]["parentId"]]["children"].push(list[i]);
} else {
treeList.push(list[i]);
}
}
return treeList
},
后端返回list数据,根据parentId相同,处理成tree数据
最新推荐文章于 2023-02-01 16:00:32 发布