Skip to content

Commit 4989d65

Browse files
committed
docs: update treeNode
1 parent ea0540f commit 4989d65

File tree

5 files changed

+108
-11
lines changed

5 files changed

+108
-11
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ const tree = array2tree(tree2array([/* tree */]))
4545

4646
| function | return | description |
4747
| ----------------------------------------- | ------ | ------------------------------------------------------------------- |
48-
| `randomId(prefix = '')` | string | generate random id with prefix, like `i_fang05da21` |
48+
| `randomId(prefix = '')` | string | generate random id with prefix, like `i_9fang05da21` |
4949
| `array2tree(array, [options])` | array | array to tree with leaf and deep |
5050
| `arrayTrace(array, id, [options])` | array | trace source of id from array |
5151
| `arrayDeep(array, [options], [deep = 1])` | int | get max deep of array |

docs/arrayNode.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# 列表节点
22

3+
```js
4+
arrayNode(array, id, [options])
5+
```
6+
37
根据主键的值从列表中溯源,返回**从根到自身**顺序的主键数组,如:`[id1, id12, id121]`
48

59
## 参数

docs/index.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ titleTemplate: JavaScript树实用工具
66

77
hero:
88
name: tree-array
9-
tagline: JavaScript 树状数组结构实用工具
9+
tagline: JavaScript树实用工具
1010
actions:
1111
- theme: brand
1212
text: 文 档
@@ -16,10 +16,10 @@ hero:
1616
link: https://github.com/axolo/tree-array
1717

1818
features:
19-
- title: 💡 实用第一
19+
- title: 💡 易用实用
2020
details: 来源于实际项目,在实际项目中不断优化,数据结构适配桌面端、移动端和小程序的 tree、cascader、picker 等常见组件,确保实用。
2121
- title: ⚙️ 配置灵活
2222
details: 可对主键、父键、子键、叶子、层级等键名进行配置,支持自动生成主键、父键、叶子、层级等关键数据,满足不同项目需求。
23-
- title: 🔌 使用轻松
23+
- title: 🔌 轻便小巧
2424
details: 压缩后仅 1.1KB,且无其他依赖,并提供 CommonJS 等模块标准支持,可轻松嵌入到项目中。
2525
---

docs/intro.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# 简介
22

3-
`tree-array` 是一组久经考验的 `JavaScript` 树状数组结构实用工具集合
3+
`tree-array` 是一组久经考验的 `JavaScript` 树状结构数据实用工具集合
44

55
::: tip 深拷贝
66
推荐使用 [lodash.clonedeep] 深拷贝,以避免原始数据遭到不必要的篡改。

docs/treeNode.md

Lines changed: 99 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,106 @@
1-
# treeNode
2-
3-
get path of id from tree by id, like `[id1, id12, id121]`
4-
5-
## 调用
1+
# 树节点
62

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

7+
根据主键的值从树中溯源,返回**从根到自身**顺序的主键数组,如:`[id1, id12, id121]`
8+
9+
## 参数
10+
11+
| 参数 | 类型 | 默认 | 说明 |
12+
| --------- | -------- | ---- | -------------------------------------------------- |
13+
| `tree` | `tree` | | [树状结构数据](./param.md#tree) |
14+
| `id` | `any` | | [主键](./param.md#id)的值,如:`chartProjectMyTwo` |
15+
| `options` | `object` | | [配置选项](./param.md#options) |
16+
1117
## 返回
1218

13-
array
19+
| 参数 | 类型 | 说明 |
20+
| ---- | ------- | ---------------------------- |
21+
| * | `array` | 从根到自身顺序溯源的主键数组 |
22+
23+
## 示例
24+
25+
::: code-group
26+
```js [调用]
27+
import { treeNode } 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+
treeNode(tree, 'chartProjectMyTwo') // array of id
96+
```
97+
98+
```json [结果]
99+
[
100+
"chart",
101+
"chartProject",
102+
"chartProjectMy",
103+
"chartProjectMyTwo"
104+
]
105+
```
106+
:::

0 commit comments

Comments
 (0)