From a57536c494d3d00740171186c95130ce0a80314f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=8F=A3=E5=8F=A3=E5=8F=A3?= <17975121@qq.com> Date: Fri, 23 Aug 2024 06:00:05 +0000 Subject: [PATCH] =?UTF-8?q?update=20src/utils/tree.ts.=20tree.ts=E4=B8=AD?= =?UTF-8?q?=E7=9A=84treeToString=E9=94=99=E8=AF=AF=EF=BC=8C=E4=BF=AE?= =?UTF-8?q?=E5=A4=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 口口口 <17975121@qq.com> --- src/utils/tree.ts | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/src/utils/tree.ts b/src/utils/tree.ts index 91059ef91..4bf5b1256 100644 --- a/src/utils/tree.ts +++ b/src/utils/tree.ts @@ -374,15 +374,18 @@ export const treeToString = (tree: any[], nodeId) => { return node.name } let str = '' + let list = [] function performAThoroughValidation(arr) { 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 } } @@ -391,10 +394,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 } -- Gitee