toList

将树形结构转换回扁平数组。

toList

toList 方法将树形结构转换回扁平数组。

用法

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 键名的配置对象。

返回值

T[]
返回一个扁平的节点数组。

Changelog

No recent changes
Copyright © 2024 - 2025 YiXuan - MIT License