You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
36 lines
753 B
36 lines
753 B
export function getItemByIdInCascader(arr, vals, idName, childName) {
|
|
let item = arr.find((v) => v[idName] == vals[0]);
|
|
if (vals.length > 1) {
|
|
return [
|
|
item,
|
|
...getItemByIdInCascader(
|
|
item[childName],
|
|
vals.slice(1),
|
|
idName,
|
|
childName
|
|
),
|
|
];
|
|
} else {
|
|
return [item];
|
|
}
|
|
}
|
|
|
|
export function collapse(arr, childName) {
|
|
if (arr.length > 0) {
|
|
let ret = [...arr];
|
|
arr.forEach((element) => {
|
|
let childs = element[childName];
|
|
if (childs && Array.isArray(childs)) {
|
|
ret.push(...collapse(childs, childName));
|
|
}
|
|
});
|
|
return ret;
|
|
} else {
|
|
return [];
|
|
}
|
|
}
|
|
|
|
export default {
|
|
getItemByIdInCascader,
|
|
collapse,
|
|
};
|
|
|