Methods
(inner) toTree(list, itemKeyopt, topItemValueopt, parentIdKeyopt) → {Array}
表格数据转换为树形结构
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
list | Array | 平铺的数据数组,每一项应该包含一个{itemKey}和[parentIdKey]:[{id,name,parentId},{id,name,parentId}] | ||
itemKey | String | <optional> | 'id' | 每一项的唯一键 |
topItemValue | Number | | <optional> | 0 | 最上级菜单的唯一键的值 |
parentIdKey | String | <optional> | 'parentId' | 每一项的父级键 |
- Source
Returns:
[{id,name,parentId,children:[{id,name,parentId}]}]
- Type:
- Array
Example
const list = [
{id:1,name:'item-1',parentId:0},
{id:2,name:'item-2',parentId:0},
{id:3,name:'item-3',parentId:1}
]
toTree(list)
// [
// {id:1,name:'item-1',parentId:0,children:[{id:3,name:'item-3',parentId:1}]},
// {id:2,name:'item-2',parentId:0},
// ]
(inner) treeToCascaderValue(tree, focusId, itemKeyopt) → {Array}
树形数据转换为级联值
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
tree | Array | 树形结构 | ||
focusId | Number | | 当前选中的值 | ||
itemKey | Number | | <optional> | 'id' | 树形结构需要取出对比的键 |
- Source
Returns:
[1,2,3] 树形结构数组
- Type:
- Array
Example
const tree = [
{id:1,name:'item-1',parentId:0,children:[{id:3,name:'item-3',parentId:1}]},
{id:2,name:'item-2',parentId:0},
]
treeToCascaderValue(tree,3)
// [1,3]