mirror of
https://github.com/vbenjs/vue-vben-admin.git
synced 2025-01-25 02:58:43 +08:00
parent
72dbe574d3
commit
8d218ec8d5
@ -181,14 +181,16 @@ export function useTree(treeDataRef: Ref<TreeDataItem[]>, getFieldNames: Compute
|
||||
function getSelectedNode(key: KeyType, list?: TreeItem[], selectedNode?: TreeItem | null) {
|
||||
if (!key && key !== 0) return null;
|
||||
const treeData = list || unref(treeDataRef);
|
||||
const { key: keyField, children: childrenField } = unref(getFieldNames);
|
||||
if (!keyField) return;
|
||||
treeData.forEach((item) => {
|
||||
if (selectedNode?.key || selectedNode?.key === 0) return selectedNode;
|
||||
if (item.key === key) {
|
||||
if (item[keyField] === key) {
|
||||
selectedNode = item;
|
||||
return;
|
||||
}
|
||||
if (item.children && item.children.length) {
|
||||
selectedNode = getSelectedNode(key, item.children, selectedNode);
|
||||
if (item[childrenField!] && item[childrenField!].length) {
|
||||
selectedNode = getSelectedNode(key, item[childrenField!], selectedNode);
|
||||
}
|
||||
});
|
||||
return selectedNode || null;
|
||||
|
Loading…
Reference in New Issue
Block a user