树形结构,通过子节点,获取祖先节点
作者:
芸芸众生ing | 来源:发表于
2022-11-03 16:05 被阅读0次function getValuePath(list , val ) {
const { value, children } = this.PROPS;
const arr = [];
getObject(list, 0);
function getObject(listObj , idx ) {
let bool = false;
for (let item of listObj) {
if (item[value] === val) {
bool = true;
arr[idx] = item;
break;
} else if (item[children]?.length) {
bool = getObject(item[children], idx + 1);
if (bool) {
arr[idx] = item;
break;
}
}
}
return bool;
}
return arr;
},
本文标题:树形结构,通过子节点,获取祖先节点
本文链接:https://www.haomeiwen.com/subject/psqutdtx.html
网友评论