【react+antd】当你使用了可选择的table【rowSelection】,却在操作后无法清除已选择状态
关键代码:
const [selectedKeys, setSelectedKeys] = useState([]);
const [selectRows, setSelectRows] = useState([]);
const [selectedSingleRows, setSelectedSingleRows] = useState([]); //单条编辑
const rowSelection = {
// type: 'checkbox',
selectedRowKeys: selectedKeys,
onChange: (selectedRowKeys, selectedRows) => {
selectedRows = selectedRows.map(String);
console.log("RowKeys",selectedRows);
// setSelectedRows(selectedRows);
setSelectedKeys(selectedRowKeys);
setSelectRows(selectedRows);
},
// onSelect(selectedRows) {
// setSelectRows(selectedRows);
// },
// onSelectAll(selectedRows) {
// setSelectRows(selectedRows);
// }
// getCheckboxProps: (record) => ({
// checked: (selectedRows.indexOf(record.id)>-1?true:false)
// }),
};
const onFinish = (values) => {
console.log('Success:', values);
console.log('ids',selectRows);
batchEdit({ ids:modalTitle=='批量编辑'?selectedKeys:selectedSingleRows,checkState:values.checkState,extendCheck:values.extendCheck}).then((res) => {
if (res.data.code !== 200) {
message.error(res.data.msg);
} else {
search();
setBatchEditVisible(false);
setSelectRows([])
setSelectedKeys([])
}
});
};