From 9bf8efc4f85211b55a8eccd2f132d540e6df972b Mon Sep 17 00:00:00 2001 From: zaodonganqi <131591012+zaodonganqi@users.noreply.github.com> Date: Sun, 6 Apr 2025 22:14:07 +0800 Subject: [PATCH] update search (#6) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Add files via upload * Add files via upload 搜索树 --- src/App.vue | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/src/App.vue b/src/App.vue index 88216c9..34d719c 100644 --- a/src/App.vue +++ b/src/App.vue @@ -186,18 +186,17 @@ const handleTreeSearch = () => { // 添加树节点过滤函数 const filterTreeNodes = (nodes, searchText) => { return nodes.map(node => { + const isSelfMatch = isPinyinMatch(node.title, searchText); + + if (isSelfMatch) { + return { ...node }; + } + const newNode = { ...node }; if (newNode.children) { newNode.children = filterTreeNodes(newNode.children, searchText); } - - if ( - isPinyinMatch(newNode.title, searchText) || - (newNode.children && newNode.children.length > 0) - ) { - return newNode; - } - return null; + return (newNode.children?.length > 0) ? newNode : null; }).filter(Boolean); };