From 439dd093c4e0708ac3616e18ff655454525b2c90 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=A2=81=E7=81=8F?= Date: Sun, 12 Jan 2020 10:42:20 +0800 Subject: [PATCH] update table tree --- examples/routers/table.vue | 2 +- src/components/table/table.vue | 23 ++++++++++++++++++++--- 2 files changed, 21 insertions(+), 4 deletions(-) diff --git a/examples/routers/table.vue b/examples/routers/table.vue index 4ca736ed..48e39d33 100644 --- a/examples/routers/table.vue +++ b/examples/routers/table.vue @@ -359,7 +359,7 @@ }, ]; callback(data); - }, 100); + }, 1000); }, addData () { const d = this.data1[3]; diff --git a/src/components/table/table.vue b/src/components/table/table.vue index 50724436..b565dc21 100644 --- a/src/components/table/table.vue +++ b/src/components/table/table.vue @@ -796,16 +796,30 @@ this.loadData(sourceData, children => { this.$set(sourceData, '_loading', false); if (children.length) { - // todo this.$set(sourceData, 'children', children); - const data2 = this.getDataByRowKey(rowKey); - data2._isShowChildren = !data2._isShowChildren; + this.$nextTick(() => { + const newData = this.getDataByRowKey(rowKey); + newData._isShowChildren = !newData._isShowChildren; + this.updateDataStatus(rowKey, '_showChildren', newData._isShowChildren); + }); } }); return; } data._isShowChildren = !data._isShowChildren; + this.updateDataStatus(rowKey, '_showChildren', data._isShowChildren); + }, + /** + * @description 当修改某内置属性,如 _isShowChildren 时,因当将原 data 对应 _showChildren 也修改,否则修改 data 时,状态会重置 + * @param rowKey rowKey + * @param key 原数据对应的字段 + * @param value 修改的值 + * */ + // todo 单选、多选等状态可能也需要更新原数据 + updateDataStatus (rowKey, key, value) { + const data = this.getBaseDataByRowKey(rowKey, this.data); + this.$set(data, key, value); }, getDataByRowKey (rowKey, objData = this.objData) { let data = null; @@ -1208,6 +1222,9 @@ } newRow.children = this.makeChildrenObjData(newRow); } + // else if ('_loading' in newRow && newRow.children && newRow.children.length === 0) { + // newRow._isShowChildren = false; + // } data[index] = newRow; }); return data;