Commit 63f2e0f4c4bb15b08ac91f1490adfa5cd14cdf41

Authored by 梁灏
1 parent 99d0429e

fixed Table bug when remove a row of data

when Cell has a button to delete row data, clickCurrentRow will throw
an error, so clone a data
Showing 1 changed file with 10 additions and 5 deletions   Show diff stats
src/components/table/table.vue
... ... @@ -173,7 +173,8 @@
173 173 bodyHeight: 0,
174 174 bodyRealHeight: 0,
175 175 scrollBarWidth: getScrollBarSize(),
176   - currentContent: this.content
  176 + currentContent: this.content,
  177 + cloneData: deepCopy(this.data) // when Cell has a button to delete row data, clickCurrentRow will throw an error, so clone a data
177 178 };
178 179 },
179 180 computed: {
... ... @@ -357,16 +358,16 @@
357 358 }
358 359 }
359 360 this.objData[_index]._isHighlight = true;
360   - const oldData = oldIndex < 0 ? null : JSON.parse(JSON.stringify(this.data[oldIndex]));
361   - this.$emit('on-current-change', JSON.parse(JSON.stringify(this.data[_index])), oldData);
  361 + const oldData = oldIndex < 0 ? null : JSON.parse(JSON.stringify(this.cloneData[oldIndex]));
  362 + this.$emit('on-current-change', JSON.parse(JSON.stringify(this.cloneData[_index])), oldData);
362 363 },
363 364 clickCurrentRow (_index) {
364 365 this.highlightCurrentRow (_index);
365   - this.$emit('on-row-click', JSON.parse(JSON.stringify(this.data[_index])));
  366 + this.$emit('on-row-click', JSON.parse(JSON.stringify(this.cloneData[_index])));
366 367 },
367 368 dblclickCurrentRow (_index) {
368 369 this.highlightCurrentRow (_index);
369   - this.$emit('on-row-dblclick', JSON.parse(JSON.stringify(this.data[_index])));
  370 + this.$emit('on-row-dblclick', JSON.parse(JSON.stringify(this.cloneData[_index])));
370 371 },
371 372 getSelection () {
372 373 let selectionIndexes = [];
... ... @@ -663,6 +664,10 @@
663 664 this.objData = this.makeObjData();
664 665 this.rebuildData = this.makeDataWithSortAndFilter();
665 666 this.handleResize();
  667 + // here will trigger before clickCurrentRow, so use async
  668 + setTimeout(() => {
  669 + this.cloneData = deepCopy(this.data);
  670 + }, 0);
666 671 },
667 672 deep: true
668 673 },
... ...