用法
toList 方法将树形结构转换回扁平数组。
example.ts
import { Tree } from '@movk/core'
const tree = [
{
id: 1,
pid: 0,
name: 'root',
children: [
{ id: 2, pid: 1, name: 'child 1' },
{ id: 3, pid: 1, name: 'child 2' }
]
}
]
const list = Tree.toList(tree)
/*
list 将会是:
[
{ id: 1, pid: 0, name: 'root' },
{ id: 2, pid: 1, name: 'child 1' },
{ id: 3, pid: 1, name: 'child 2' }
]
*/
API
toList<T extends TreeNode>(tree: T[], config?: TreeConfig): T[]
参数
tree
T[] required
树形结构的节点数组。
config
TreeConfig
用于自定义树形结构中
id, pid, children 键名的配置对象。id
string
可选。指定节点唯一标识符的键名。默认为 "id"。
pid
string
可选。指定节点父级标识符的键名。默认为 "pid"。
children
string
可选。指定子节点数组的键名。默认为 "children"。
返回值
T[]
返回一个扁平的节点数组。
Changelog
No recent changes