Commit 0985c87b6930d261f46dbff812a9b89fdce97448
1 parent
56c7cc0e
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 | 81 | methods: { |
82 | 82 | compileFlatState () { // so we have always a relation parent/children of each node |
83 | 83 | let keyCounter = 0; |
84 | + let childrenKey = this.childrenKey; | |
84 | 85 | const flatTree = []; |
85 | 86 | function flattenChildren(node, parent) { |
86 | 87 | node.nodeKey = keyCounter++; |
87 | 88 | flatTree[node.nodeKey] = { node: node, nodeKey: node.nodeKey }; |
88 | 89 | if (typeof parent != 'undefined') { |
89 | 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 | 99 | this.stateTree.forEach(rootNode => { |
... | ... | @@ -109,11 +110,11 @@ |
109 | 110 | if (node.checked == parent.checked && node.indeterminate == parent.indeterminate) return; // no need to update upwards |
110 | 111 | |
111 | 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 | 114 | this.$set(parent, 'indeterminate', !parent.checked); |
114 | 115 | } else { |
115 | 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 | 119 | this.updateTreeUp(parentKey); |
119 | 120 | }, |
... | ... | @@ -144,8 +145,8 @@ |
144 | 145 | for (let key in changes) { |
145 | 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 | 150 | this.updateTreeDown(child, changes); |
150 | 151 | }); |
151 | 152 | } | ... | ... |