update table tree

This commit is contained in:
梁灏 2020-01-12 10:42:20 +08:00
parent a410eb2dca
commit 439dd093c4
2 changed files with 21 additions and 4 deletions

View file

@ -359,7 +359,7 @@
}, },
]; ];
callback(data); callback(data);
}, 100); }, 1000);
}, },
addData () { addData () {
const d = this.data1[3]; const d = this.data1[3];

View file

@ -796,16 +796,30 @@
this.loadData(sourceData, children => { this.loadData(sourceData, children => {
this.$set(sourceData, '_loading', false); this.$set(sourceData, '_loading', false);
if (children.length) { if (children.length) {
// todo
this.$set(sourceData, 'children', children); this.$set(sourceData, 'children', children);
const data2 = this.getDataByRowKey(rowKey); this.$nextTick(() => {
data2._isShowChildren = !data2._isShowChildren; const newData = this.getDataByRowKey(rowKey);
newData._isShowChildren = !newData._isShowChildren;
this.updateDataStatus(rowKey, '_showChildren', newData._isShowChildren);
});
} }
}); });
return; return;
} }
data._isShowChildren = !data._isShowChildren; 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) { getDataByRowKey (rowKey, objData = this.objData) {
let data = null; let data = null;
@ -1208,6 +1222,9 @@
} }
newRow.children = this.makeChildrenObjData(newRow); newRow.children = this.makeChildrenObjData(newRow);
} }
// else if ('_loading' in newRow && newRow.children && newRow.children.length === 0) {
// newRow._isShowChildren = false;
// }
data[index] = newRow; data[index] = newRow;
}); });
return data; return data;