我设置了默认勾选13,第一次提交(132)是对的,第二次,页面上还勾选着上次提交的,没有按getCheckboxProps配置的渲染,然后onChange这,输出的是上一次提交的(132)+本次默认(13)+新勾的(45)= [1, 3, 2, 1, 3, 4, 5]我是百思不得其解。class User extends Interval { constructor(props) { super(props); this.state = { synCode: [], } } render() { console.log(this.state.synCode); const _this = this; const rowSelection = { getCheckboxProps(record) { return { defaultChecked: record.leader === 1, // 配置默认勾选的列 }; }, onChange(selectedRowKeys) { console.log('新来的',selectedRowKeys); // console.log('原来的',_this.state.synCode); _this.setState({synCode: selectedRowKeys}) }, }; return ( <Table rowSelection={rowSelection} columns={columns} dataSource={this.state.data} /> ); }}
4 回答
慕工程0101907
TA贡献1887条经验 获得超5个赞
当想清除勾选的时候,设置this.state.selectedRowKeys=[];
const rowSelection = {
onChange: (selectedRowKeys, selectedRows) => {
this.state.nowIds = selectedRowKeys.join(',');
this.state.selectedRowKeys = selectedRowKeys;
this.setState({
selectedRowKeys:this.state.selectedRowKeys,
})
},
getCheckboxProps: record => ({
disabled:record.receiveStatus !=0,
receiveStatus: record.receiveStatus,
}),
selectedRowKeys:this.state.selectedRowKeys,
};
添加回答
举报
0/150
提交
取消