const treeData = (item) => {
if (item.parent && item.parent.length > 0) {
let _parent = data.taskData.filter((data) => data.id == item.parent);
if (_parent && _parent.length > 0) {
if (dataList.filter((data) => data.id == _parent[0].id).length == 0) {
dataList = [...dataList, ..._parent];
}
if (_parent[0].parent && _parent[0].parent.length > 0) treeData(_parent[0]);
}
}
};
dataList.forEach((item) => {
treeData(item);
});
标签:parent,--,JavaScript,dataList,item,length,&&,data,节点
From: https://blog.51cto.com/dd118/7389137