Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 9574643

Browse files
JesonhuPanJiaChen
authored andcommitted
fix[Tree-Table]: fixed update item data bug (PanJiaChen#1692)
1 parent 8edf209 commit 9574643

File tree

2 files changed

+15
-11
lines changed

2 files changed

+15
-11
lines changed

src/components/TreeTable/index.vue

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,19 @@ export default {
146146
this.selcetRecursion(child, select, children)
147147
})
148148
}
149+
},
150+
updateTreeNode(item) {
151+
return new Promise(resolve => {
152+
const { _id, _parent } = item
153+
const index = _id.split('-').slice(-1)[0] // get last index
154+
if (_parent) {
155+
_parent.children.splice(index, 1, item)
156+
resolve(this.data)
157+
} else {
158+
this.data.splice(index, 1, item)
159+
resolve(this.data)
160+
}
161+
})
149162
}
150163
}
151164
}

src/views/tree-table/custom/index.vue

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -127,17 +127,8 @@ export default {
127127
this.tempItem = Object.assign({}, row)
128128
this.dialogFormVisible = true
129129
},
130-
updateItem() {
131-
const data = this.$refs.TreeTable.getData()
132-
const { _id } = this.tempItem
133-
134-
for (let i = 0; i < data.length; i++) {
135-
if (data[i]._id === _id) {
136-
data.splice(i, 1, Object.assign({}, this.tempItem))
137-
break
138-
}
139-
}
140-
130+
async updateItem() {
131+
await this.$refs.TreeTable.updateTreeNode(this.tempItem)
141132
this.dialogFormVisible = false
142133
},
143134
addMenuItem(row, type) {

0 commit comments

Comments
 (0)