mirror of
https://github.com/vbenjs/vue-vben-admin.git
synced 2025-01-26 12:48:48 +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) {
|
function getSelectedNode(key: KeyType, list?: TreeItem[], selectedNode?: TreeItem | null) {
|
||||||
if (!key && key !== 0) return null;
|
if (!key && key !== 0) return null;
|
||||||
const treeData = list || unref(treeDataRef);
|
const treeData = list || unref(treeDataRef);
|
||||||
|
const { key: keyField, children: childrenField } = unref(getFieldNames);
|
||||||
|
if (!keyField) return;
|
||||||
treeData.forEach((item) => {
|
treeData.forEach((item) => {
|
||||||
if (selectedNode?.key || selectedNode?.key === 0) return selectedNode;
|
if (selectedNode?.key || selectedNode?.key === 0) return selectedNode;
|
||||||
if (item.key === key) {
|
if (item[keyField] === key) {
|
||||||
selectedNode = item;
|
selectedNode = item;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (item.children && item.children.length) {
|
if (item[childrenField!] && item[childrenField!].length) {
|
||||||
selectedNode = getSelectedNode(key, item.children, selectedNode);
|
selectedNode = getSelectedNode(key, item[childrenField!], selectedNode);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
return selectedNode || null;
|
return selectedNode || null;
|
||||||
|
Loading…
Reference in New Issue
Block a user