Skip to content

Commit 53ed88c

Browse files
committed
docs: update treeSub
1 parent cad2e15 commit 53ed88c

File tree

1 file changed

+112
-6
lines changed

1 file changed

+112
-6
lines changed

docs/treeSub.md

Lines changed: 112 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,119 @@
1-
# treeSub
2-
3-
get sub tree by id, like `{ id, parentId, children: [] }`
4-
5-
## 调用
1+
# 剪取子树
62

73
```js
84
treeSub(tree, id, [options])
95
```
106

7+
根据主键从树中剪取一棵子树, 如:`{ id, parentId, children: [] }`
8+
9+
## 参数
10+
11+
| 参数 | 类型 | 默认 | 说明 |
12+
| --------- | -------- | ---- | ------------------------------------------- |
13+
| `tree` | `tree` | | [树状结构数据](./param.md#tree) |
14+
| `id` | `any` | | [主键](./param.md#id)的值,如:`chartIndex` |
15+
| `options` | `object` | | [配置选项](./param.md#options) |
16+
1117
## 返回
1218

13-
tree
19+
| 参数 | 类型 | 说明 |
20+
| ---- | -------- | ---------------------------------- |
21+
| * | `object` | 剪取下的子树,注意其类型为**对象** |
22+
23+
## 示例
24+
25+
::: code-group
26+
```js [调用]
27+
import { treeSub } from '@axolo/tree-array'
28+
29+
const tree = [{
30+
id: 'home',
31+
path: '/home',
32+
parentId: null
33+
}, {
34+
id: 'chart',
35+
path: '/chart',
36+
parentId: null,
37+
children: [{
38+
id: 'chartIndex',
39+
path: '/chart/index',
40+
parentId: 'chart',
41+
children: [{
42+
id: 'chartIndexTop',
43+
path: '/chart/index/top',
44+
parentId: 'chartIndex'
45+
}, {
46+
id: 'chartIndexActive',
47+
path: '/chart/index/active',
48+
parentId: 'chartIndex',
49+
children: [{
50+
id: 'chartIndexActiveMy',
51+
path: '/chart/index/active/my',
52+
parentId: 'chartIndexActive'
53+
}]
54+
}]
55+
}, {
56+
id: 'chartReview',
57+
path: '/chart/review',
58+
parentId: 'chart'
59+
}, {
60+
id: 'chartProject',
61+
path: '/chart/project',
62+
parentId: 'chart',
63+
children: [{
64+
id: 'chartProjectYou',
65+
path: '/chart/project/you',
66+
parentId: 'chartProject',
67+
test: true
68+
}, {
69+
id: 'chartProjectMy',
70+
path: '/chart/project/my',
71+
parentId: 'chartProject',
72+
children: [{
73+
id: 'chartProjectMyOne',
74+
path: '/chart/project/my/one',
75+
parentId: 'chartProjectMy'
76+
}, {
77+
id: 'chartProjectMyTwo',
78+
path: '/chart/project/my/two',
79+
parentId: 'chartProjectMy'
80+
}]
81+
}]
82+
}]
83+
}, {
84+
id: 'smile',
85+
path: '/smile',
86+
parentId: null,
87+
children: [{
88+
id: 'smileIndex',
89+
path: '/smile/index',
90+
parentId: 'smile',
91+
test: true
92+
}]
93+
}]
94+
95+
treeSub(tree, 'chartIndex') // object of sub tree
96+
```
97+
98+
```json [结果]
99+
{
100+
"id": "chartIndex",
101+
"path": "/chart/index",
102+
"parentId": "chart",
103+
"children": [{
104+
"id": "chartIndexTop",
105+
"path": "/chart/index/top",
106+
"parentId": "chartIndex"
107+
}, {
108+
"id": "chartIndexActive",
109+
"path": "/chart/index/active",
110+
"parentId": "chartIndex",
111+
"children": [{
112+
"id": "chartIndexActiveMy",
113+
"path": "/chart/index/active/my",
114+
"parentId": "chartIndexActive"
115+
}]
116+
}]
117+
}
118+
```
119+
:::

0 commit comments

Comments
 (0)