el-table同步勾选多条
需求: 功能需要实现选择一个,同一物料下的其他的都同步选中或者同步取消
templete
<template>
<el-table
ref="table"
border
:data="tableData"
style="width: 100%"
highlight-current-row
:span-method="objectSpanMethod"
@select="select" //关键代码
@selection-change="handleSelectionChange"
>
<el-table-column
type="selection"
width="55"
/>
<el-table-column
label="序号"
type="index"
width="50"
/>
// ...此处正常逻辑省略
</el-table>
</template>
export default {
data() {
return {...}
},
methods: {
select(selection, row) { //关键代码
const flag = selection.includes(row)
if (this.tableData && this.tableData.length) {
this.tableData.forEach(item => {
if (item.materialId === row.materialId) {
this.$refs.table.toggleRowSelection(item, flag)
}
})
}
},
// ...省略其他无关代码
}
}