• 将平级结构数组转换为树形结构

    Parameters

    • flatList: TreeNode[]

      平级结构数组

    • options: {
          childrenKey: string;
          idKey: string;
          parentKey: string;
      } = ...

      配置选项

      • childrenKey: string

        子节点数组的键名,默认为 "children"

      • idKey: string

        节点唯一标识的键名,默认为 "id"

      • parentKey: string

        父节点标识的键名,默认为 "parentId"

    Returns TreeNode[]

    返回树形结构数据

    Example

    const list = [
    { id: '1', name: 'Node1', parentId: '0' },
    { id: '2', name: 'Node2', parentId: '1' },
    { id: '2-1', name: 'Node2-1', parentId: '2' },
    { id: '3', name: 'Node3', parentId: '1' }
    ];
    const tree = convertFlatToTree(list);
    // 返回树形结构:
    // [
    // {
    // id: '1',
    // name: 'Node1',
    // parentId: '0',
    // children: [
    // { id: '2', name: 'Node2', parentId: '1', children: [ { id: '2-1', name: 'Node2-1', parentId: '2', children: [] }] },
    // { id: '3', name: 'Node3', parentId: '1', children: [] }
    // ]
    // }
    // ]

Generated using TypeDoc