树形结构查询父级
const findPatentValue = (array,id,labelID = "id",childrenId = "children") => {
if (!id || !Array.isArray(array)) return [];
const result = [];
let valid = false;
const seek = (array, id) => {
let parentValue = "";
const up = (array, id, lastlabel) => {
array.forEach((v) => {
const val = v[labelID];
const child = v[childrenId];
if (val === id) {
valid = true;
parentValue = lastlabel;
return;
}
if (child && child.length) up(child, id, val);
});
};
up(array, id);
if (parentValue) {
result.unshift(parentValue);
seek(array, parentValue);
}
};
seek(array, id);
return valid ? [...result, id] : [];
};