Skip to content

Commit 81c3a19

Browse files
committed
docs: update arrayTrace
1 parent bfe99e5 commit 81c3a19

File tree

3 files changed

+92
-14
lines changed

3 files changed

+92
-14
lines changed

docs/arrayTrace.md

+84-6
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,91 @@
1-
# arrayTrace
2-
3-
trace source of id from array
4-
5-
## 调用
1+
# 数组溯源
62

73
```js
84
arrayTrace(array, id, [options])
95
```
106

7+
根据主键的值从数组中溯源,返回从根到自身溯源的顺序数组。
8+
9+
## 参数
10+
11+
| 参数 | 类型 | 默认 | 说明 |
12+
| --------- | -------- | ---- | --------------------------------------------------- |
13+
| `array` | `array` | | [列表结构数据](./param.md#array) |
14+
| `id` | `any` | | [主键](./param.md#id)的值,如:`chartIndexActiveMy` |
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 { arrayTrace } from '@axolo/tree-array'
28+
29+
const array = [{
30+
id: 'chart',
31+
path: '/chart',
32+
parentId: null
33+
}, {
34+
id: 'chartIndex',
35+
path: '/chart/index',
36+
parentId: 'chart'
37+
}, {
38+
id: 'chartIndexActive',
39+
path: '/chart/index/active',
40+
parentId: 'chartIndex'
41+
}, {
42+
id: 'chartIndexActiveMy',
43+
path: '/chart/index/active/my',
44+
parentId: 'chartIndexActive'
45+
}, {
46+
id: 'chartReview',
47+
path: '/chart/review',
48+
parentId: 'chart'
49+
}, {
50+
id: 'chartProject',
51+
path: '/chart/project',
52+
parentId: 'chart'
53+
}, {
54+
id: 'smile',
55+
path: '/smile',
56+
parentId: null
57+
}, {
58+
id: 'smileIndex',
59+
path: '/smile/index',
60+
parentId: 'smile',
61+
test: true
62+
}]
63+
64+
arrayTrace(array, 'chartIndexActiveMy')
65+
```
66+
67+
```json [返回]
68+
[
69+
{
70+
"id": "chart",
71+
"path": "/chart",
72+
"parentId": null
73+
},
74+
{
75+
"id": "chartIndex",
76+
"path": "/chart/index",
77+
"parentId": "chart"
78+
},
79+
{
80+
"id": "chartIndexActive",
81+
"path": "/chart/index/active",
82+
"parentId": "chartIndex"
83+
},
84+
{
85+
"id": "chartIndexActiveMy",
86+
"path": "/chart/index/active/my",
87+
"parentId": "chartIndexActive"
88+
}
89+
]
90+
```
91+
:::

docs/randomId.md

+6-6
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
randomId(prefix = '')
55
```
66

7-
生成一个由小写字母和数字组成的自定义前缀(`prefix`)的随机字符串,如:`i_fang05da21`
7+
生成一个由小写字母和数字组成的自定义前缀(`prefix`)的随机字符串,如:`i_9fang05da21`
88

99
::: danger 碰撞几率
1010
基于`Math.random()`生成,碰撞几率取决于`Math.random()`的随机性,可能不适用于大数据场景。
@@ -18,20 +18,20 @@ randomId(prefix = '')
1818

1919
## 返回
2020

21-
| 参数 | 类型 | 说明 |
22-
| ---- | -------- | ------------------------------ |
23-
| * | `string` | 随机字符串,如:`i_fang05da21` |
21+
| 参数 | 类型 | 说明 |
22+
| ---- | -------- | ------------------------------- |
23+
| * | `string` | 随机字符串,如:`i_9fang05da21` |
2424

2525
## 示例
2626

2727
::: code-group
2828
```js [调用]
2929
import { randomId } from '@axolo/tree-array'
3030

31-
randomId('i_') // i_fang05da21
31+
randomId('i_') // i_9fang05da21
3232
```
3333

3434
```text [返回]
35-
i_fang05da21
35+
i_9fang05da21
3636
```
3737
:::

src/test/array.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,6 @@
2929
}, {
3030
"id": "smileIndex",
3131
"path": "/smile/index",
32-
"test": true,
33-
"parentId": "smile"
32+
"parentId": "smile",
33+
"test": true
3434
}]

0 commit comments

Comments
 (0)