数组转树结构,删除空的子节点数组

This commit is contained in:
aixianling
2023-04-07 08:36:04 +08:00
parent df940bc035
commit e420628475

View File

@@ -54,6 +54,12 @@ const $arr2tree = (list, config = {}) => {
itemMap[pid].children.push(treeItem)
} else result.push(treeItem)
}
const removeNullChildren = node => {
if (node[children] && node[children].length > 0) {
node[children].map(c => removeNullChildren(c))
} else delete node[children]
}
result.forEach(removeNullChildren)
return result
}