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;
},
网友评论