@@ -8,7 +8,7 @@ Description:
8
8
9
9
<template >
10
10
<div class =" container" >
11
- <myTree :nodes =" data " />
11
+ <myTree :nodes =" computedTree " />
12
12
</div >
13
13
</template >
14
14
@@ -23,16 +23,36 @@ export default {
23
23
},
24
24
25
25
setup () {
26
- const data = ref ( [
26
+ const data = [
27
27
{
28
- label: " father" ,
28
+ id: 1 ,
29
+ label: ' Animal' ,
29
30
nodes: [
30
31
{
31
- label: " son1" ,
32
+ id: 2 ,
33
+ label: ' Dog' ,
34
+ },
35
+ {
36
+ id: 3 ,
37
+ label: ' Cat' ,
38
+ nodes: [
39
+ {
40
+ id: 4 ,
41
+ label: ' Egyptian Mau Cat' ,
42
+ },
43
+ {
44
+ id: 5 ,
45
+ label: ' Japanese Bobtail Cat' ,
46
+ },
47
+ ],
32
48
},
33
49
],
34
50
},
35
- ]);
51
+ {
52
+ id: 6 ,
53
+ label: ' People' ,
54
+ },
55
+ ];
36
56
return {
37
57
data,
38
58
};
@@ -42,59 +62,93 @@ export default {
42
62
... mapState ([" componentMap" , " activeComponent" ]),
43
63
// Returns project tree on re-render
44
64
computedTree () {
45
- console .log (" buildtree" , this .buildTree ());
46
- return this .buildTree ();
65
+ const builtTree = [this .buildTree ()];
66
+ console .log (" buildtree" , builtTree);
67
+ return builtTree;
47
68
},
48
69
},
49
70
50
71
data () {
51
72
return {
52
73
tree: null ,
53
74
treeKey: " key" ,
54
- testTree: {
55
- label: " father" ,
75
+ testTree: [
76
+ {
77
+ id: 1 ,
78
+ label: ' Animal' ,
56
79
nodes: [
57
80
{
58
- label: " son1" ,
81
+ id: 2 ,
82
+ label: ' Dog' ,
83
+ },
84
+ {
85
+ id: 3 ,
86
+ label: ' Cat' ,
87
+ nodes: [
88
+ {
89
+ id: 4 ,
90
+ label: ' Egyptian Mau Cat' ,
91
+ },
92
+ {
93
+ id: 5 ,
94
+ label: ' Japanese Bobtail Cat' ,
95
+ },
96
+ ],
59
97
},
60
98
],
61
99
},
100
+ {
101
+ id: 6 ,
102
+ label: ' People' ,
103
+ },
104
+ ],
62
105
};
63
106
},
64
107
65
108
methods: {
66
109
// Called by transformToTree, formats componentMap
67
110
formatComponentMap (compMap ) {
111
+ // console.log('COMP MAP: ', compMap);
68
112
let result = [];
69
- Object .values (compMap).forEach ((compData ) => {
113
+ // Id to apply to each component, in accordance with Vue3Tree syntax
114
+ let id = 1 ;
115
+ const values = Object .values (compMap)
116
+ // console.log('FormatComponentMap: ', values);
117
+ values .forEach ((compData ) => {
70
118
result .push ({
71
- name: compData .componentName ,
72
- children: compData .children ,
119
+ id: id++ ,
120
+ label: compData .componentName , // previously was labeled 'name'
121
+ nodes: compData .children , // previously was labeled 'children'
73
122
});
74
123
});
124
+
125
+
126
+ console .log (' FORMATCOMPONENTMAP result: ' , result);
75
127
return result;
76
128
},
77
129
// Called by buildTree, transforms componentMap
130
+ // we need to change this to clean the data and transform it to something usable by vue3tree
78
131
transformToTree (data ) {
79
132
let result = {};
80
- const nodes = {};
133
+ const temp = {};
81
134
const formattedData = this .formatComponentMap (data);
82
135
formattedData .forEach ((component ) => {
83
- if (! nodes [component .name ]) {
84
- nodes [component .name ] = { name : component .name , children : [] };
85
- result = nodes ;
136
+ if (! temp [component .label ]) {
137
+ temp [component .label ] = { label : component .label , nodes : [] };
138
+ result = temp ;
86
139
}
87
- component .children .forEach ((child ) => {
88
- if (! nodes [child]) nodes [child] = { name : child, children : [] };
89
- nodes [component .name ]. children .push (nodes [child]);
140
+ component .nodes .forEach ((child ) => {
141
+ if (! temp [child]) temp [child] = { label : child, nodes : [] };
142
+ temp [component .label ]. nodes .push (temp [child]);
90
143
});
91
144
});
92
- // console.log(nodes)
93
- // console.log(result)
145
+ // console.log('transformToTree nodes:', nodes)
146
+ console .log (' TRANSFORMTOTREE result ' , result)
94
147
return result;
95
148
},
96
149
// Called by computedTree, calls transformToTree
97
150
buildTree () {
151
+ console .log (' COMPONENT MAP:' , this .componentMap );
98
152
let build = this .transformToTree (this .componentMap );
99
153
return build[" App" ];
100
154
},
0 commit comments