思路:向上查找父级树
loopTreeFindChecked(node) {
const findParentTree = (data, parentId) => {
if (!data) return;
data.forEach(item => {
if (item.id === parentId) {
this.checkedTreeList.unshift({ id: parentId, name: item.name, type: item.type });
if (item.parentId > 0) {
findParentTree(this.treeList, item.parentId);
}
} else {
findParentTree(item.children, parentId);
}
});
};
this.checkedTreeList = [{ id: node.id, name: node.name, type: node.type }];
if (node.parentId > 0) findParentTree(this.treeList, node.parentId);
}
标签:node,子树,父级,findParentTree,item,parentId,type,id
From: https://www.cnblogs.com/c0lmd0wn/p/18320324