#6950 Fixes performance issue for TreeSelect component
parent
0c5a0925c1
commit
3782131fac
|
@ -452,22 +452,11 @@ export default {
|
||||||
onOverlayKeydown(event) {
|
onOverlayKeydown(event) {
|
||||||
if (event.code === 'Escape') this.hide();
|
if (event.code === 'Escape') this.hide();
|
||||||
},
|
},
|
||||||
findSelectedNodes(node, keys, selectedNodes) {
|
fillNodeMap(node, nodeMap) {
|
||||||
if (node) {
|
nodeMap[node.key] = node;
|
||||||
if (this.isSelected(node, keys)) {
|
|
||||||
selectedNodes.push(node);
|
|
||||||
delete keys[node.key];
|
|
||||||
}
|
|
||||||
|
|
||||||
if (Object.keys(keys).length && node.children) {
|
if (node.children?.length) {
|
||||||
for (let childNode of node.children) {
|
node.children.forEach(children => this.fillNodeMap(children, nodeMap))
|
||||||
this.findSelectedNodes(childNode, keys, selectedNodes);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
for (let childNode of this.options) {
|
|
||||||
this.findSelectedNodes(childNode, keys, selectedNodes);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
isSelected(node, keys) {
|
isSelected(node, keys) {
|
||||||
|
@ -520,13 +509,24 @@ export default {
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
computed: {
|
computed: {
|
||||||
|
nodeMap() {
|
||||||
|
const nodeMap = {};
|
||||||
|
|
||||||
|
this.options?.forEach(node => this.fillNodeMap(node, nodeMap))
|
||||||
|
|
||||||
|
return nodeMap;
|
||||||
|
},
|
||||||
selectedNodes() {
|
selectedNodes() {
|
||||||
let selectedNodes = [];
|
let selectedNodes = [];
|
||||||
|
|
||||||
if (this.d_value && this.options) {
|
if (this.d_value && this.options) {
|
||||||
let keys = { ...this.d_value };
|
Object.keys(this.d_value).forEach(key => {
|
||||||
|
const node = this.nodeMap[key];
|
||||||
|
|
||||||
this.findSelectedNodes(null, keys, selectedNodes);
|
if (this.isSelected(node, this.d_value)) {
|
||||||
|
selectedNodes.push(node)
|
||||||
|
}
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
return selectedNodes;
|
return selectedNodes;
|
||||||
|
|
Loading…
Reference in New Issue