Ver código fonte

Tree: delete current node after it removed (#14604)

Jeff Wen 6 anos atrás
pai
commit
6ae9f0838f

+ 4 - 0
packages/tree/src/model/tree-store.js

@@ -91,7 +91,11 @@ export default class TreeStore {
 
   remove(data) {
     const node = this.getNode(data);
+
     if (node && node.parent) {
+      if (node === this.currentNode) {
+        this.currentNode = null;
+      }
       node.parent.removeChild(node);
     }
   }

+ 3 - 0
test/unit/specs/tree.spec.js

@@ -494,10 +494,13 @@ describe('Tree', () => {
   it('remove', (done) => {
     vm = getTreeVm(':props="defaultProps" node-key="id"');
     const tree = vm.$children[0];
+    tree.setCurrentKey(1);
+    expect(tree.getCurrentNode().id).to.equal(1);
     tree.remove(1);
     vm.$nextTick(() => {
       expect(vm.data[0].id).to.equal(2);
       expect(tree.getNode(1)).to.equal(null);
+      expect(tree.getCurrentNode()).to.equal(null);
       done();
     });
   });