沈斌
2017-12-15 f9b157566af34b8dc28ba10b34d025ac04f3168b
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
export function generateData(nodes, _x, _y, _z, _preKey?: any, _tns?: any) {
    const preKey = _preKey || '0';
    const tns = _tns || nodes;
 
    const children = [];
    for (let i = 0; i < _x; i++) {
      const key = `${preKey}-${i}`;
      tns.push({ name: key, id: key, disableCheckbox: i === 1 });
      if (i < _y) {
        children.push(key);
      }
    }
    if (_z < 0) {
      return tns;
    }
    const level = _z - 1;
    children.forEach((key, index) => {
      tns[index].children = [];
      return generateData(nodes, _x, _y, level, key, tns[index].children);
    });
  }