Function: treeToList()
ts
function treeToList<T>(trees, options?): T[];Flattens a tree structure into a flat array, removing the children property. 将树结构展平为平面数组,移除children属性。
This function traverses a tree structure breadth-first and collects all nodes into a single flat array. The children property is removed from each node. The order of nodes in the result follows a breadth-first traversal pattern. 此函数广度优先遍历树结构,将所有节点收集到单个平面数组中。 每个节点的children属性会被移除。结果中节点的顺序遵循广度优先遍历模式。
Type Parameters
| Type Parameter | Description |
|---|---|
T extends { [key: string]: any; } | The type of the tree nodes / 树节点的类型 |
Parameters
| Parameter | Type | Description |
|---|---|---|
trees | T[] | Array of tree root nodes / 树根节点数组 |
options | TreeToListOptions<T> | Configuration options for the conversion / 转换的配置选项 |
Returns
T[]
Flat array of all nodes without children properties / 不包含children属性的所有节点的平面数组
Example
ts
const tree = [{ id: 1, children: [{ id: 2 }] }]
treeToList(tree)
// => [{ id: 1 }, { id: 2 }]Since
1.2.0