@zhaoyifeng/easy-tree
v1.0.5
Published
常用树操作
Downloads
4
Readme
easy-tree
常用的树工具
$ npm install @zhaoyifeng/easy-tree
import * as easyTree from '@zhaoyifeng/easy-tree'
// or
import { flat, filterNode } from '@zhaoyifeng/easy-tree'
API
flat(tree)
扁平化
const data = flat(treeData)
findNode(tree, predicate)
查找
const data = findNode(treeData, (node) => node.key === '0')
filterNode(tree, predicate)
筛选
const data = filterNode(treeData, (node) => node.key === '0')
insertBefore(tree, predicate, object)
向节点前插入数据
const data = insertBefore(treeData, (node) => node.key === '0', { title: '0000', key: '0000' })
insertAfter(tree, predicate, object)
向节点后插入数据
const data = insertAfter(treeData, (node) => node.key === '0', { title: '0000', key: '0000' })
insertToChild(tree, predicate, isBefore = false)
插入到子节点
const data = insertToChild(treeData, (node) => node.key === '1', { title: '0000', key: '0000' }, true)
updateNode(tree, predicate)
修改节点
const data = updateNode(treeData, (node) => node.key === '0', (node) => ({ ...node, title: '0000' }))
deleteNode(tree, predicate)
删除节点
const data = deleteNode(treeData, (node) => node.key === '1')
replaceNode(tree, func)
替换树节点对象
const data = replaceNode(treeData, node => ({
id: node.id
}))