From 9574643e927788826082c05db59a2f0ca458f4c3 Mon Sep 17 00:00:00 2001 From: Jesonhu Date: Tue, 12 Mar 2019 13:23:59 +0800 Subject: [PATCH] fix[Tree-Table]: fixed update item data bug (#1692) --- src/components/TreeTable/index.vue | 13 +++++++++++++ src/views/tree-table/custom/index.vue | 13 ++----------- 2 files changed, 15 insertions(+), 11 deletions(-) diff --git a/src/components/TreeTable/index.vue b/src/components/TreeTable/index.vue index cbe1eb60..9ce7a503 100644 --- a/src/components/TreeTable/index.vue +++ b/src/components/TreeTable/index.vue @@ -146,6 +146,19 @@ export default { this.selcetRecursion(child, select, children) }) } + }, + updateTreeNode(item) { + return new Promise(resolve => { + const { _id, _parent } = item + const index = _id.split('-').slice(-1)[0] // get last index + if (_parent) { + _parent.children.splice(index, 1, item) + resolve(this.data) + } else { + this.data.splice(index, 1, item) + resolve(this.data) + } + }) } } } diff --git a/src/views/tree-table/custom/index.vue b/src/views/tree-table/custom/index.vue index 6f9142a6..11e47912 100644 --- a/src/views/tree-table/custom/index.vue +++ b/src/views/tree-table/custom/index.vue @@ -127,17 +127,8 @@ export default { this.tempItem = Object.assign({}, row) this.dialogFormVisible = true }, - updateItem() { - const data = this.$refs.TreeTable.getData() - const { _id } = this.tempItem - - for (let i = 0; i < data.length; i++) { - if (data[i]._id === _id) { - data.splice(i, 1, Object.assign({}, this.tempItem)) - break - } - } - + async updateItem() { + await this.$refs.TreeTable.updateTreeNode(this.tempItem) this.dialogFormVisible = false }, addMenuItem(row, type) {