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