Skip to content

guo-jianqiang/common-tree-function

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

总结一些常用的tree操作函数

函数介绍

  • 深度优先遍历
  • 广度优先遍历
  • 深拷贝
  • 查找匹配树节点并返回当前节点信息及深度
  • 树条件过滤
  • 数组转树
  • 树转数组
  • 获取当前节点路径

安装

npm install common-tree-func

使用

demo1

import tree from 'common-tree-func'

const obj = {
  name: '小明'
  age: 25,
  children: [
    {
      name: '小红',
      age: 1
    }
  ]
}

const cloneObj = tree.deepClone(obj)

demo2

import tree, {filterTree} from 'common-tree-func'

const obj = [
  {
    name: '小明'
    age: 25,
    children: [
      {
        name: '小红',
        age: 1
      }
    ]
  },
  {
    name: '张xx',
    age: 33
  }
]
// 树过滤
const newTree = filterTree(obj, node => node.name === '小红')

About

总结常用的tree操作函数

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published