//array是查找的树结构列表,dictKey是根据字段查找
find(array, dictKey) {
let stack = [];
let going = true;
let walker = (array, dictKey) => {
array.forEach(item => {
if (!going) return;
stack.push(item["id"]);
if (item["id"] === dictKey) {
going = false;
} else if (item["children"]) {
walker(item["children"], dictKey);
} else {
stack.pop();
}
});
if (going) stack.pop();
};
walker(array, dictKey);
return stack;
},
树结构递归查找父级
最新推荐文章于 2022-06-22 18:08:29 发布