element的table组件中,如果要设置默认选中,需要使用组件提供的方法toggleRowSelection,但是这玩意会触发组件绑定的selection-change事件,但是selection-change又是手动点击事件,不能被toggleRowSelection触发,解决方法是:
加一把锁 flag
// 初始化设置默认table选中
changeFilterIndex(idx) {
this.flag = true;
this.curIndex = idx;
this.staticViewpanes.forEach(v => {
const flag = !!this.filterList[this.curIndex].viewPanelList.filter(item => item.viewId === v.viewId)[0];
// console.log('flag', flag);
this.$refs.multipleTable.toggleRowSelection(v, flag);
});
this.flag = false;
},
// 手动点击选中
selectionChange(val) {
if (this.flag) return;
this.$set(this.filterList, this.curIndex, {
...this.filterList[this.curIndex],
viewPanelList: [...val]
});
// this.filterList[this.curIndex].viewPanelList = [...val];
// console.log('this.selectedViews', this.selectedViews)
},