Skip to content

通用参数

在功能函数中经常会见以下通用参数:

名称说明
options配置选项
array列表结构数据
tree树状结构数据

options

配置选项是 key-value 形式的键值对,用于动态定义数据的关键键名。

参数类型默认值说明
idKeystringid主键名
parentKeystringparentId父键名
childrenKeystringchildren子键名
leafKeystringleaf叶子键名
leafValueanytrue叶子值
deepKeystringdeep深度键名
deepValuenumber0根级深度值

当对应键被定义时,其定义值覆盖默认值;键未定义的仍使用键默认值。如:

js
{
  idKey: 'key',
  parentKey: 'parentKey',
  leafKey: 'isLeaf',
  deepKey: 'level',
  deepValue: 1
}

array

列表数据结构,示例如下:

json
[{
  "id": "chart",
  "path": "/chart",
  "parentId": null
}, {
  "id": "chartIndex",
  "path": "/chart/index",
  "parentId": "chart"
}, {
  "id": "chartIndexActive",
  "path": "/chart/index/active",
  "parentId": "chartIndex"
}, {
  "id": "chartIndexActiveMy",
  "path": "/chart/index/active/my",
  "parentId": "chartIndexActive"
}, {
  "id": "chartReview",
  "path": "/chart/review",
  "parentId": "chart"
}, {
  "id": "chartProject",
  "path": "/chart/project",
  "parentId": "chart"
}, {
  "id": "smile",
  "path": "/smile",
  "parentId": null
}, {
  "id": "smileIndex",
  "path": "/smile/index",
  "test": true,
  "parentId": "smile"
}]

tree

树状结构数据,示例如下:

json
[{
  "id": "chart",
  "path": "/chart",
  "parentId": null,
  "children": [{
    "id": "chartIndex",
    "path": "/chart/index",
    "parentId": "chart",
    "children": [{
      "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"
  }]
}, {
  "id": "smile",
  "path": "/smile",
  "parentId": null,
  "children": [{
    "id": "smileIndex",
    "path": "/smile/index",
    "test": true,
    "parentId": "smile"
  }]
}]

@axolo/tree-array