update tree table async

This commit is contained in:
梁灏 2020-01-10 11:12:49 +08:00
parent 7f4315cb4e
commit 85a1bc8af0
4 changed files with 128 additions and 16 deletions

View file

@ -262,6 +262,10 @@
indentSize: {
type: Number,
default: 16
},
// 4.1.0
loadData: {
type: Function
}
},
data () {
@ -784,6 +788,23 @@
},
toggleTree (rowKey) {
const data = this.getDataByRowKey(rowKey);
// async loading
if ('_loading' in data && data._loading) return;
if ('_loading' in data && !data._loading && data.children.length === 0) {
const sourceData = this.getBaseDataByRowKey(rowKey, this.data);
this.$set(sourceData, '_loading', true);
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;
}
});
return;
}
data._isShowChildren = !data._isShowChildren;
},
getDataByRowKey (rowKey, objData = this.objData) {