15
src/App.vue
15
src/App.vue
@@ -186,18 +186,17 @@ const handleTreeSearch = () => {
|
|||||||
// 添加树节点过滤函数
|
// 添加树节点过滤函数
|
||||||
const filterTreeNodes = (nodes, searchText) => {
|
const filterTreeNodes = (nodes, searchText) => {
|
||||||
return nodes.map(node => {
|
return nodes.map(node => {
|
||||||
|
const isSelfMatch = isPinyinMatch(node.title, searchText);
|
||||||
|
|
||||||
|
if (isSelfMatch) {
|
||||||
|
return { ...node };
|
||||||
|
}
|
||||||
|
|
||||||
const newNode = { ...node };
|
const newNode = { ...node };
|
||||||
if (newNode.children) {
|
if (newNode.children) {
|
||||||
newNode.children = filterTreeNodes(newNode.children, searchText);
|
newNode.children = filterTreeNodes(newNode.children, searchText);
|
||||||
}
|
}
|
||||||
|
return (newNode.children?.length > 0) ? newNode : null;
|
||||||
if (
|
|
||||||
isPinyinMatch(newNode.title, searchText) ||
|
|
||||||
(newNode.children && newNode.children.length > 0)
|
|
||||||
) {
|
|
||||||
return newNode;
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}).filter(Boolean);
|
}).filter(Boolean);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user