跨页选择后数据回显处理注意事项:
1、this.$refs.crud.toggleRowSelection(item, true) // 回显数据遍历切换选中状态即可计数表格选中项
2、需要表格回显打勾 item必须是表格数据列表中的某一条
所以只需在页面初始化时created里表格数据请求后(如:请求表格数据函数返回一个Promise) 执行下面代码即可
created() {
// 用于初始化回显数据this.fetchMaterialList().then(() => {
this.$nextTick(() => {
let tableIds = this.tableData.map(o => o.id)
this.selectData.forEach(item => {
if (tableIds.includes(item.id)) {
let obj = this.tableData.find(o => o.id == item.id)
// obj 必须是表格里的某条数据才回显
this.$refs.crud.toggleRowSelection(obj, true)
} else {
// 用来给当前表格已选择项计数
this.$refs.crud.toggleRowSelection(item, true)
}
})
})
})
},