Skip to content

Commit

Permalink
docs: update treeDeep
Browse files Browse the repository at this point in the history
  • Loading branch information
axolo committed Apr 12, 2024
1 parent 1ec9acf commit ea0540f
Showing 1 changed file with 94 additions and 6 deletions.
100 changes: 94 additions & 6 deletions docs/treeDeep.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,101 @@
# treeDeep

get max deep of tree

## 调用
# 树深度

```js
treeDeep(tree, [options], [deep = 1])
```

获取树状数据结构的最大树深度。

## 参数

| 参数 | 类型 | 默认 | 说明 |
| --------- | -------- | ---- | -------------------------------- |
| `tree` | `tree` | | [树状结构数据](./param.md#tree) |
| `options` | `object` | | [配置选项](./param.md#options) |
| `deep` | `number` | `1` | 初始深度,以此基础累加到最大深度 |

## 返回

int
| 参数 | 类型 | 说明 |
| ---- | -------- | ---------- |
| * | `number` | 最大树深度 |

## 示例

::: code-group
```js [调用]
import { treeDeep } from '@axolo/tree-array'

const tree = [{
id: 'home',
path: '/home',
parentId: null
}, {
id: 'chart',
path: '/chart',
parentId: null,
children: [{
id: 'chartIndex',
path: '/chart/index',
parentId: 'chart',
children: [{
id: 'chartIndexTop',
path: '/chart/index/top',
parentId: 'chartIndex'
}, {
id: 'chartIndexActive',
path: '/chart/index/active',
parentId: 'chartIndex',
children: [{
id: 'chartIndexActiveMy',
path: '/chart/index/active/my',
parentId: 'chartIndexActive'
}]
}]
}, {
id: 'chartReview',
path: '/chart/review',
parentId: 'chart'
}, {
id: 'chartProject',
path: '/chart/project',
parentId: 'chart',
children: [{
id: 'chartProjectYou',
path: '/chart/project/you',
parentId: 'chartProject',
test: true
}, {
id: 'chartProjectMy',
path: '/chart/project/my',
parentId: 'chartProject',
children: [{
id: 'chartProjectMyOne',
path: '/chart/project/my/one',
parentId: 'chartProjectMy'
}, {
id: 'chartProjectMyTwo',
path: '/chart/project/my/two',
parentId: 'chartProjectMy'
}]
}]
}]
}, {
id: 'smile',
path: '/smile',
parentId: null,
children: [{
id: 'smileIndex',
path: '/smile/index',
parentId: 'smile',
test: true
}]
}]

treeDeep(tree) // 4
```

```json [结果]
4
```
:::

0 comments on commit ea0540f

Please sign in to comment.