猿问

antd的Table表格默认会勾选上次勾选的,怎么清除

我设置了默认勾选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} />

        );

    }

}


繁星点点滴滴
浏览 9708回答 4
4回答

慕工程0101907

当想清除勾选的时候,设置this.state.selectedRowKeys=[];const rowSelection = {&nbsp; &nbsp; onChange: (selectedRowKeys, selectedRows) => {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; this.state.nowIds = selectedRowKeys.join(',');&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; this.state.selectedRowKeys = selectedRowKeys;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; this.setState({&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; selectedRowKeys:this.state.selectedRowKeys,&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; })&nbsp; &nbsp; &nbsp; &nbsp; },&nbsp; &nbsp; &nbsp; &nbsp; getCheckboxProps: record => ({&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; disabled:record.receiveStatus !=0,&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; receiveStatus: record.receiveStatus,&nbsp; &nbsp; &nbsp; &nbsp; }),&nbsp; &nbsp; &nbsp; &nbsp; selectedRowKeys:this.state.selectedRowKeys,&nbsp; &nbsp; };

小怪兽爱吃肉

操作完成后,设置selectedRow: [],selectedKeys: []
随时随地看视频慕课网APP

相关分类

JavaScript
我要回答