今天在做项目时有遇到表格里多选的选中内容后再次打开默认选中打钩,ele单元格用toggleRowSelection(row, true)回显时row必须返回当前列表渲染用的数据,自己存的数据是无效的,而且用toggleRowSelection这个方法时就会报 报错 toggleRowSelection‘ of undefined。
解决方法是 :加了个this.$nextTick(function () {})在外边,问题解决
this.$nextTick(function () {
this.tableData.forEach(row => {
if (row.enable) {
this.$refs.multipleTable.toggleRowSelection(row, true);
}
})
});
// 按数组回显选择框
echoCheckbox() {
...
this.selectObj[this.page].forEach(_item => {
this.tableData.forEach(item => {
if (this.whetherInclude(_item, item)) {
// 这里的item必须是渲染列表的数据 必要时请使用this.$nextTick
this.$nextTick(() => this.$refs.checkTable.toggleRowSelection(item, true))
}
})
})
...
}
自己在做项目中写的代码片段 容易自己理解
this.choseList = this.datalist.filter((item) =>{
return item.emplyStatus == "1"
})
this.$nextTick(function(){
this.dataList.forEach((item,index) => {
this.choseList.forEach((value,i) =>{
if(item.uapp == value.uapp){
this.$refs.multipleTable.toggleRowSelection(value,true)
}
})
})
})