Skip to content

Commit 915fc52

Browse files
authored
Tree: fix add node bug in lazy mode (#12265)
1 parent 7158ddc commit 915fc52

File tree

1 file changed

+11
-7
lines changed

1 file changed

+11
-7
lines changed

packages/tree/src/model/node.js

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -285,11 +285,13 @@ export default class Node {
285285

286286
removeChildByData(data) {
287287
let targetNode = null;
288-
this.childNodes.forEach(node => {
289-
if (node.data === data) {
290-
targetNode = node;
288+
289+
for (let i = 0; i < this.childNodes.length; i++) {
290+
if (this.childNodes[i] === data) {
291+
targetNode = this.childNodes[i];
292+
break;
291293
}
292-
});
294+
}
293295

294296
if (targetNode) {
295297
this.removeChild(targetNode);
@@ -442,9 +444,11 @@ export default class Node {
442444
}
443445
});
444446

445-
oldData.forEach((item) => {
446-
if (!newDataMap[item[NODE_KEY]]) this.removeChildByData(item);
447-
});
447+
if (!this.store.lazy) {
448+
oldData.forEach((item) => {
449+
if (!newDataMap[item[NODE_KEY]]) this.removeChildByData(item);
450+
});
451+
}
448452

449453
newNodes.forEach(({ index, data }) => {
450454
this.insertChild({ data }, index);

0 commit comments

Comments
 (0)