🌺前言
js树的扁平化
javascript
/**
* 将树转化为数组
* @param {Array} tree
* @returns
*/
export default function useDeepFindAllTreeNode (tree) {
const result = []
const findNode = (tree) => {
if (!(tree && tree.length)) return
for (let i = 0; i < tree.length; i++) {
result.push(tree[i])
if (tree[i].children && tree[i].children.length) {
findNode(tree[i].children)
}
}
}
findNode(tree)
return result
}
文章最后更新于 2024-08-20 16:20:42
作者:徐徐版权声明:转载请注明文章出处
留言

~~空空如也