Skip to content

Latest commit

 

History

History
74 lines (70 loc) · 1.24 KB

README.md

File metadata and controls

74 lines (70 loc) · 1.24 KB

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