效果:页面中有一个推送对象的容器,点击后会弹出用户选择的dialog表格,表格可多选,选完后点确定会把选中的用户信息放进容器中,当容器为空时在表格中选中再确定没问题,但当容器中有用户信息时,再点击选中表格内容会覆盖已有内容
解决办法:
...
//这是弹出dialog的方法,i是当前容器的下标
showDialog(i) {
this.dialogVisible = true;
if (i != this.pushIndex) {
this.$nextTick(() => {
this.$refs.multipleTable.clearSelection();
});
}
this.pushIndex = i;
//userArr表示容器中已有的数据
const userArr = this.details[i].user;
if (userArr.length > 0) {
//先清空表格中所有的选中项
this.$nextTick(() => {
this.$refs.multipleTable.clearSelection();
});
userArr.forEach(user => {
//遍历已有数据,取出数据中的用户登录ID
let loginName = user.substr(user.indexOf("/") + 1, user.length);
const form = {
limit: 2,
page: 1,
keyword: loginName
};
//将用户登录ID作为搜索关键词通过搜索接口来请求用户的完整数据对象
this.noEncryptionAixos
.get(apiUserList, { params: form })
.then(res => {
if (res.code == 200) {
this.$nextTick(() => {
this.getTableData()
const userObj = res.data.list[0];
//请求到完整数据后将数据所在行选中,这样绑定上就不会出现覆盖的情况了
this.$refs.multipleTable.toggleRowSelection(userObj, true);
});
}
});
});
} else {
this.$nextTick(() => {
this.$refs.multipleTable.clearSelection();
});
}
...
最终效果: