gpt4 book ai didi

reactjs - 在 ant 设计表选择中通过 getCheckboxProps 设置 defaultChecked 有什么问题?

转载 作者:行者123 更新时间:2023-12-04 15:35:01 34 4
gpt4 key购买 nike

我正在使用表格作为单选组。像这样:

<Table
dataSource={keyData}
columns={keyColumns}
rowSelection={keySelection}
pagination={false}
/>
<Form.Item >
{getFieldDecorator('pendingKey', {
initialValue: data?.pendingKey,
rules: [
{
required: type === 'pending_key',
message: 'Select a key'
}
]
})(<div />) // to show eorror message
}
</Form.Item>

现在在 getCheckboxProps 中设置 defaultSelected 真的很有帮助:

getCheckboxProps: record => ({
defaultChecked: record.key === data?.pendingKey
})

但是当我这样做时 ant design 会显示错误消息:

Warning: [antd: Table] Do not set `checked` or `defaultChecked` in `getCheckboxProps`. Please use `selectedRowKeys` instead. 

这究竟有什么问题?如何让输入不受控制并关闭此消息?

最佳答案

rowSelection中添加selectedRowKeys属性设置选中行

<Table
rowSelection={{
type: 'radio',
selectedRowKeys: ['1'], // Use this attribute
onChange: () => {}
}}
//...Omitting
/>

关于reactjs - 在 ant 设计表选择中通过 getCheckboxProps 设置 defaultChecked 有什么问题?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60055302/

34 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com