a-table切换分页selectionRows数据丢失
使用jeecg-boot框架,Ant-design-vue组件库遇到的问题:
a-table切换分页selectionRows数据丢失
<a-table
ref="table"
size="middle"
:scroll="{ x: true }"
:loading="loading"
bordered
rowKey="id"
:columns="columnsUser"
:dataSource="dataSource"
:pagination="pagination"
:row-selection="{ selectedRowKeys: selectedRowKeys, onChange: onSelectChange }"
>
</a-table>
解决方法:
onChange:选中项发生变化时的回调
onSelectChange(selectedRowKeys, selectionRows) {
this.selectionRows=this.selectionRows.concat(selectionRows)
this.selectionRows=this.selectionRows.filter(item=>this.selectedRowKeys.indexOf(item.id) != -1)
//数组对象去重
let map = new Map();
for (let item of this.selectionRows) {
if (!map.has(item.id)) {
map.set(item.id, item);
};
};
this.selectionRows = [...map.values()];
}