easydata-tree
v1.0.3
Published
Easy tree data processing.
Downloads
12
Maintainers
Readme
EasyTree
Easy tree data processing.
Install
npm i easydata-tree //or yarn add easydata-tree
CDN
<script src="https://unpkg.com/easydata-tree/dist/index.min.js"></script>
<script>
new EasyTree({
id: 'id',
parentId: 'pid',
label: 'name',
children: 'child'
})
</script>
Usage
const EasyTree = require("easydata-tree")
new EasyTree({
id: 'id',
parentId: 'pid',
label: 'name',
children: 'child'
})
let tree = [{
name: '-一级 1',
id: '一级 1',
z: 1,
child: [{
name: '-二级 1-1',
id: '二级 1-1',
z: 3,
child: [{
name: '-三级 1-1-1',
id: '三级 1-1-1',
z: 2
}]
}]
}, {
name: '-一级 2',
id: '一级 2',
child: [{
name: '-二级 2-1',
id: '二级 2-1',
child: [{
name: '-三级 2-1-1',
id: '三级 2-1-1'
}]
}, {
name: '-二级 2-2',
id: '二级 2-2',
child: [{
name: '-三级 2-2-1',
id: '三级 2-2-1'
}]
}]
}, {
name: '-一级 3',
id: '一级 3',
child: [{
name: '-二级 3-1',
id: '二级 3-1',
child: [{
name: '-三级 3-1-1',
id: '三级 3-1-1'
}]
}, {
name: '-二级 3-2',
id: '二级 3-2',
child: [{
name: '-三级 3-2-1',
id: '三级 3-2-1'
}]
}]
}]
toArray(parentId)
- {String|Number} parentId
tree.toArray()
toTree(parentId)
- {String|Number} parentId
tree.toArray().toTree()
findPath(id)
- {String|Number} id
required
tree.findPath('三级 3-1-1')
- {String|Number} id
findChildren(id)
- {String|Number} id
required
tree.findPath('一级 3')
- {String|Number} id