diff --git a/src/utils/tree.ts b/src/utils/tree.ts index e5db503f8..b983c2f94 100644 --- a/src/utils/tree.ts +++ b/src/utils/tree.ts @@ -374,6 +374,7 @@ export const treeToString = (tree: any[], nodeId) => { return node.name } let str = '' + let list = [] function performAThoroughValidation(arr) { if (typeof arr === 'undefined' || !Array.isArray(arr) || arr.length === 0) { @@ -381,11 +382,13 @@ export const treeToString = (tree: any[], nodeId) => { } for (const item of arr) { if (item.id === nodeId) { - str += ` / ${item.name}` + list.push(item.name) + // str += ` / ${item.name}` return true } else if (typeof item.children !== 'undefined' && item.children.length !== 0) { - str += ` / ${item.name}` + // str += ` / ${item.name}` if (performAThoroughValidation(item.children)) { + list.push(item.name) return true } } @@ -394,10 +397,16 @@ export const treeToString = (tree: any[], nodeId) => { } for (const item of tree) { + list = [] str = `${item.name}` if (performAThoroughValidation(item.children)) { break } } + if (list.length > 0) { + list.reverse().forEach((name) => { + str += ` / ${name}` + }) + } return str }