-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmock.mjs
80 lines (77 loc) · 1.63 KB
/
mock.mjs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
import buildTree from "./index.js"
const dataSource = [
{
id: 1,
parentId: undefined,
groupName: {
name: '经理1',
count: 10
},
},
{
id: 2,
parentId: null,
groupName: {
name: '经理2',
count: 1
},
},
{
id: 3,
parentId: 0,
groupName: {
name: '经理3',
count: 2
},
},
{
id: 4,
parentId: 1,
groupName: {
name: '主管1',
count: 4
},
},
{
id: 5,
parentId: 1,
groupName: {
name: '主管2',
count: 6
},
},
{
id: 6,
parentId: 4,
groupName: {
name: '小组1',
count: 4
},
},
{
id: 7,
parentId: 5,
groupName: {
name: '小组2',
count: 4
},
},
{
id: 8,
parentId: 2,
groupName: {
name: '主管3',
count: 0
},
},
{
id: 9,
parentId: 3,
groupName: {
name: '主管4',
count: 0
},
},
];
const result = '[{"id":1,"groupName":{"name":"经理1","count":10},"children":[{"id":4,"parentId":1,"groupName":{"name":"主管1","count":4},"children":[{"id":6,"parentId":4,"groupName":{"name":"小组1","count":4}}]},{"id":5,"parentId":1,"groupName":{"name":"主管2","count":6},"children":[{"id":7,"parentId":5,"groupName":{"name":"小组2","count":4}}]}]},{"id":2,"parentId":null,"groupName":{"name":"经理2","count":1},"children":[{"id":8,"parentId":2,"groupName":{"name":"主管3","count":0}}]},{"id":3,"parentId":0,"groupName":{"name":"经理3","count":2},"children":[{"id":9,"parentId":3,"groupName":{"name":"主管4","count":0}}]}]';
console.log(JSON.stringify(buildTree(dataSource)) === result);