鍍金池/ 問答/HTML/ antd的Table表格默認(rèn)會勾選上次勾選的,怎么清除

antd的Table表格默認(rèn)會勾選上次勾選的,怎么清除

我設(shè)置了默認(rèn)勾選13,第一次提交(132)是對的,第二次,頁面上還勾選著上次提交的,沒有按getCheckboxProps配置的渲染,然后onChange這,輸出的是上一次提交的(132)+本次默認(rèn)(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, // 配置默認(rèn)勾選的列
                };
            },
            onChange(selectedRowKeys) {
                console.log('新來的',selectedRowKeys);
                // console.log('原來的',_this.state.synCode);
                _this.setState({synCode: selectedRowKeys})

            },
        };
       
        return (
            <Table rowSelection={rowSelection} columns={columns} dataSource={this.state.data} />
        );
    }
}
回答
編輯回答
愛是癌

@moveStar 這個表格,我是封裝成一個組件用的,之后我給這個組件加了一個key就解決了。我看網(wǎng)上各種說清selectedRowKeys的,沒弄明白怎么清。

2018年9月16日 11:47