Skip to content

bytrix/jack-utils

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

14 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

jack-utils

const tree = [
    {
        name: 'A',
        children: [
            {
                name: 'B',
                children: [
                    {
                        name: 'D',
                    },
                    {
                        name: 'E'
                    }
                ]
            },
            {
                name: 'C',
                children: [
                    {
                        name: 'F'
                    },
                    {
                        name: 'G'
                    }
                ]
            }
        ]
    }
]

获取遍历结果

const tree = new Tree({
    data: tree,
    key: 'name'
})
const keys = tree.getKeys() // -> [A,B,D,E,C,F,G]

遍历节点的回调函数

const tree = new Tree({
    data: tree,
    key: 'name'
}).walk(([children, index]) => {
    const child = children[index]
    if(child?.name === 'B') {
        return false
    }
    return true
})
// output:
// [{
// 	"name": "A",
// 	"children": [{
// 		"name": "C",
// 		"children": [{
// 			"name": "F",
// 			"children": []
// 		}, {
// 			"name": "G",
// 			"children": []
// 		}]
// 	}]
// }]

API

  • arrayIntegrate
  • uniqConcat

About

个人工具库

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published