Commit 0985c87b6930d261f46dbff812a9b89fdce97448

Authored by vanppo
1 parent 56c7cc0e

:bug: Fix issue #3236

Showing 1 changed file with 9 additions and 8 deletions   Show diff stats
src/components/tree/tree.vue
@@ -81,18 +81,19 @@ @@ -81,18 +81,19 @@
81 methods: { 81 methods: {
82 compileFlatState () { // so we have always a relation parent/children of each node 82 compileFlatState () { // so we have always a relation parent/children of each node
83 let keyCounter = 0; 83 let keyCounter = 0;
  84 + let childrenKey = this.childrenKey;
84 const flatTree = []; 85 const flatTree = [];
85 function flattenChildren(node, parent) { 86 function flattenChildren(node, parent) {
86 node.nodeKey = keyCounter++; 87 node.nodeKey = keyCounter++;
87 flatTree[node.nodeKey] = { node: node, nodeKey: node.nodeKey }; 88 flatTree[node.nodeKey] = { node: node, nodeKey: node.nodeKey };
88 if (typeof parent != 'undefined') { 89 if (typeof parent != 'undefined') {
89 flatTree[node.nodeKey].parent = parent.nodeKey; 90 flatTree[node.nodeKey].parent = parent.nodeKey;
90 - flatTree[parent.nodeKey].children.push(node.nodeKey); 91 + flatTree[parent.nodeKey][childrenKey].push(node.nodeKey);
91 } 92 }
92 93
93 - if (node.children) {  
94 - flatTree[node.nodeKey].children = [];  
95 - node.children.forEach(child => flattenChildren(child, node)); 94 + if (node[childrenKey]) {
  95 + flatTree[node.nodeKey][childrenKey] = [];
  96 + node[childrenKey].forEach(child => flattenChildren(child, node));
96 } 97 }
97 } 98 }
98 this.stateTree.forEach(rootNode => { 99 this.stateTree.forEach(rootNode => {
@@ -109,11 +110,11 @@ @@ -109,11 +110,11 @@
109 if (node.checked == parent.checked && node.indeterminate == parent.indeterminate) return; // no need to update upwards 110 if (node.checked == parent.checked && node.indeterminate == parent.indeterminate) return; // no need to update upwards
110 111
111 if (node.checked == true) { 112 if (node.checked == true) {
112 - this.$set(parent, 'checked', parent.children.every(node => node.checked)); 113 + this.$set(parent, 'checked', parent[this.childrenKey].every(node => node.checked));
113 this.$set(parent, 'indeterminate', !parent.checked); 114 this.$set(parent, 'indeterminate', !parent.checked);
114 } else { 115 } else {
115 this.$set(parent, 'checked', false); 116 this.$set(parent, 'checked', false);
116 - this.$set(parent, 'indeterminate', parent.children.some(node => node.checked || node.indeterminate)); 117 + this.$set(parent, 'indeterminate', parent[this.childrenKey].some(node => node.checked || node.indeterminate));
117 } 118 }
118 this.updateTreeUp(parentKey); 119 this.updateTreeUp(parentKey);
119 }, 120 },
@@ -144,8 +145,8 @@ @@ -144,8 +145,8 @@
144 for (let key in changes) { 145 for (let key in changes) {
145 this.$set(node, key, changes[key]); 146 this.$set(node, key, changes[key]);
146 } 147 }
147 - if (node.children) {  
148 - node.children.forEach(child => { 148 + if (node[this.childrenKey]) {
  149 + node[this.childrenKey].forEach(child => {
149 this.updateTreeDown(child, changes); 150 this.updateTreeDown(child, changes);
150 }); 151 });
151 } 152 }