|
1 |
| -# arrayTrace |
2 |
| - |
3 |
| -trace source of id from array |
4 |
| - |
5 |
| -## 调用 |
| 1 | +# 数组溯源 |
6 | 2 |
|
7 | 3 | ```js
|
8 | 4 | arrayTrace(array, id, [options])
|
9 | 5 | ```
|
10 | 6 |
|
| 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 | + |
11 | 17 | ## 返回
|
12 | 18 |
|
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 | +::: |
0 commit comments