@lstt/tools
v1.0.1
Published
Flat data to tree structure conversion
Downloads
7
Readme
@lstt/tools 工具使用指南
概述
@lstt/tools 是一款基于 TypeScript 开发的实用工具,可以将扁平数据转成树状结构。
注意:扁平数据需使用id和parentId表示层级关系。
使用 pnpm 安装
pnpm install @lstt/tools使用 npm 安装
npm install @lstt/tools快速入门
// 导入
import { listToTree } from '@lstt/tools';
// 待处理数据
const data = [
{
"id": 1,
"name": "xxx",
"sort": 0,
"state": true,
"date": 134023223232,
"parentId": 0
}
……
]
// 使用listToTree将扁平数据转成树状结构
dataTree = listToTree(data)