Methods

(inner) toTree(list, itemKeyopt, topItemValueopt, parentIdKeyopt) → {Array}

表格数据转换为树形结构

Parameters:
NameTypeAttributesDefaultDescription
listArray

平铺的数据数组,每一项应该包含一个{itemKey}和[parentIdKey]:[{id,name,parentId},{id,name,parentId}]

itemKeyString<optional>
'id'

每一项的唯一键

topItemValueNumber | String<optional>
0

最上级菜单的唯一键的值

parentIdKeyString<optional>
'parentId'

每一项的父级键

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:
NameTypeAttributesDefaultDescription
treeArray

树形结构

focusIdNumber | String

当前选中的值

itemKeyNumber | String<optional>
'id'

树形结构需要取出对比的键

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]