Tree: fix add node bug in lazy mode (#12265)

pull/12325/head
hetech 2018-08-10 15:31:28 +08:00 committed by GitHub
parent 7158ddc578
commit 915fc52a1c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 11 additions and 7 deletions

View File

@ -285,11 +285,13 @@ export default class Node {
removeChildByData(data) {
let targetNode = null;
this.childNodes.forEach(node => {
if (node.data === data) {
targetNode = node;
for (let i = 0; i < this.childNodes.length; i++) {
if (this.childNodes[i] === data) {
targetNode = this.childNodes[i];
break;
}
});
}
if (targetNode) {
this.removeChild(targetNode);
@ -442,9 +444,11 @@ export default class Node {
}
});
oldData.forEach((item) => {
if (!newDataMap[item[NODE_KEY]]) this.removeChildByData(item);
});
if (!this.store.lazy) {
oldData.forEach((item) => {
if (!newDataMap[item[NODE_KEY]]) this.removeChildByData(item);
});
}
newNodes.forEach(({ index, data }) => {
this.insertChild({ data }, index);