根据条件获取该条件下的所有树的节点.
English | 简体中文
🏠 首页
npm install @ifake/tree-path -S
# 或者
yarn add @ifake/tree-path -S
- 浏览器
// 在浏览器端, 我们暴露了一个全局变量`IFakeTP`
const { treePath } = window.IFakeTP
- ES6 Module
import { treePath } from '@ifake/tree-path'
- CommonJs
const { treePath } = require('@ifake/tree-path')
export interface TreePath {
tree: Tree
childrenKey?: string
breakCondition: BreakCondition
}
- tree 接受一个树即数组对象的形式.
- childrenKey
自定义树的嵌套的属性值, 默认是
children
- breakCondition 实时地返回当前遍历的树的节点, 根据该函数返回的条件返回所需要查询的数据结构
const sourceData = [
{
id: 1,
child: [
{
id: '1-1'
},
{
id: '1-2',
child: [
{
id: '1-2-1'
}
]
}
]
},
{
id: 2
}
]
const result = treePath({
tree: sourceData,
childrenKey: 'child',
breakCondition: treeNode => treeNode.id === '1-2-1'
})
// 结果:
[
{
id: 1,
child: [...]
},
{
id: '1-2',
child: [...]
},
{
id: '1-2-1'
}
]
yarn run test
- Website: http://loadingmore.com
- Github: @BiYuqi
欢迎贡献代码, 发现问题!
问题报告地址 issues page.
Copyright © 2020 [email protected].
当前项目的许可是MIT.
This README was generated with ❤️ by readme-md-generator