3.0.1 • Published 3 years ago

tree-walk-util v3.0.1

Weekly downloads
14
License
MIT
Repository
github
Last release
3 years ago
  • walk through a tree data
  • convert tree -> list
  • convert list -> tree

1. treeWalkDeep, treeWalkParallel:

const treeData = {
  children: [{
    id: 1,
    children: [{
      id: 2,
      children: [{
        id: 3,
        children: [{
          id: 4
        }]
      }]
    }]
  }, {
    id: 5,
    children: [{
      id: 6
    }]
  }, {
    id: 7,
    children: [{
      id: 8
    }]
  }]
}
treeWalkDeep(treeData, function (item, index, parentList, parentObj, level) {
  // item order is below
}, 'children')
1o
  2o
    3o
      4o
5o
  6o
7o
  8o
treeWalkParallel(parent, function (item, index, parentList, parentObj, level) {
  // item order is below
}, 'children')
1o
  4o
    7o
      8o
2o
  5o
3o
  6o

2. listToTree :

rawList = [
  {id: 1, pid: null},
  {id: 2, pid: null},
  {id: 3, pid: 1},
  {id: 4, pid: 2},
  {id: 5, pid: 1},
  {id: 6, pid: 3},
  {id: 7, pid: 5},
  {id: 8, pid: null},
]
listToTree(rawList, 'id', 'pid', 'children')
// will generate tree:
id1
  id3
    id6
  id5
    id7
id2
  id4
id8
3.0.1

3 years ago

3.0.0

4 years ago

2.0.5

4 years ago

2.0.4

5 years ago

2.0.3

5 years ago

2.0.2

6 years ago

0.8.0

7 years ago

0.6.0

7 years ago

0.5.1

7 years ago

0.5.0

8 years ago

0.4.1

8 years ago

0.4.0

8 years ago

0.3.0

8 years ago

0.2.2

8 years ago

0.2.1

8 years ago

0.2.0

8 years ago

0.1.0

8 years ago

0.0.5

8 years ago

0.0.3

8 years ago

0.0.2

8 years ago