代码拉取完成,页面将自动刷新
title | route |
---|---|
树形结构处理 |
/common/Tree |
树形结构有两种表示方法:子表表示法(嵌套)和父指针表示法(扁平)。
Tree 将两者进行了整合,输出一个扁平的结构,一个节点既通过 pId(指向父节点的唯一标志)建立与父节点关系,又通过 children(数组,存储子节点的唯一标志)建立与子节点的关系。
一个树形结构,为了方便处理,通常需要具备以下特点:
只支持按需引入。
import Tree from 'beeshell/dist/common/utils/Tree'
import Tree from 'beeshell/dist/common/utils/Tree'
const treeData = new Tree({
type: 'nested',
idKey: 'id',
pIdKey: 'pId',
childrenKey: 'children'
data: [
{
label: '北京',
id: 'beijing',
children: [
{ label: '朝阳区', id: 'chaoyangqu', children: [{ label: '百子湾', id: 'baiziwan' }] },
{ label: '海淀区', id: 'haidianqu' }
]
}
]
}).getData()
##API
构造函数。
const tree = new Tree({
type: 'nested',
data: nestedData
})
params keys are:
获取处理后的数据。
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。