数组转树结构,删除空的子节点数组
This commit is contained in:
@@ -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
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user