25 lines
530 B
JavaScript
25 lines
530 B
JavaScript
export const useTree = () => {
|
|
return {
|
|
filterTreeNodeByField,
|
|
}
|
|
}
|
|
|
|
function filterTreeNodeByField({ treeData, params, paramName, icon = '' }) {
|
|
return treeData.reduce((acc, node) => {
|
|
if (params.includes(node[paramName]) && !node.children) {
|
|
acc.push({ ...node, icon })
|
|
}
|
|
if (node.children) {
|
|
acc = acc.concat(
|
|
filterTreeNodeByField({
|
|
treeData: node.children,
|
|
params,
|
|
paramName,
|
|
icon: node.icon,
|
|
})
|
|
)
|
|
}
|
|
return acc
|
|
}, [])
|
|
}
|