normalizeChildren Tree
作用
深拷贝并按策略处理空的 children 属性;不影响原树结构。
签名
normalizeChildren({ tree, childrenKey='children', emptyChildren='omit' })
引入
import { normalizeChildren } from 'flit-kit'
参数
| 参数 | 类型 | 默认值 | 说明 |
|---|---|---|---|
tree | Array<object> | [] | 输入树 |
childrenKey | string | 'children' | 子节点字段名 |
emptyChildren | `'omit' | 'array' | 'null'` |
示例
const clean = normalizeChildren({ tree, emptyChildren: 'null' })
复杂度
- O(n)
返回值
Array<object>
输出
[
{
"id": 1,
"parentId": null,
"name": "A",
"sort": 2,
"children": [
{
"id": 2,
"parentId": 1,
"name": "A-1",
"sort": 1,
"children": null
},
{
"id": 3,
"parentId": 1,
"name": "A-2",
"sort": 2,
"children": null
}
]
}
]