Element的el-table懒加载操作刷新问题
el-table的懒加载非常实用,而且很方便的以树形结构展示,但是唯一不足的就是对其父子两级操作刷新不是很友好,在网上也找了很多解决方法,基本上都可以用,但是一开始觉得非常麻烦,
需要使用map集合存入,再取出刷新,
知识点来了
知识点来了
知识点来了
干货
干货
干货
其实只需要
this.
s
e
t
(
t
h
i
s
.
set(this.
set(this.refs.table.store.states.lazyTreeNodeMap,parentId,childrenData)
这么一句话就足以了,用自己逻辑进行处理,后边两个参数传值,parenntId是父级ID,childrenData是你刷新子级的数组,
代码的for循环判断,是为了满足随机操作的问题,
==tableData==是父级数组数据,和子集类型做判断,就可以随意操作子集数据了,
setTimeout加1000是为了防止异步数据加载不到的问题,
deleteInfo(item){
//...省略...
this.deleteData({
url: this.url,
query: this.$qs.stringify(query)
}).then(function(data) {
that.refreshVal(item.Type);
});
},
refreshVal(type){
this.searchInfo(type,1);
setTimeout(() => {
var parentId="";
this.tableData.forEach(data=>{
if(data.Val==type){
parentId = data.ID;
}
})
this.$set(this.$refs.table.store.states.lazyTreeNodeMap,parentId,this.childrenData)
}, 1000)
},