reactjs - 在ant设计表选择中通过getCheckboxProps设置defaultChecked有什么问题?
问题描述
我正在使用一张桌子作为广播组。像这样:
<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>
现在它真的defaultSelected
很有帮助getCheckboxProps
:
getCheckboxProps: record => ({
defaultChecked: record.key === data?.pendingKey
})
但是当我这样做时,蚂蚁设计会显示和错误消息:
Warning: [antd: Table] Do not set `checked` or `defaultChecked` in `getCheckboxProps`. Please use `selectedRowKeys` instead.
这到底有什么问题?如何保持输入不受控制并关闭此消息?
解决方案
添加selectedRowKeys
属性rowSelection
以设置选定的行
<Table
rowSelection={{
type: 'radio',
selectedRowKeys: ['1'], // Use this attribute
onChange: () => {}
}}
//...Omitting
/>
推荐阅读
- dictionary - 在冒险游戏中绘制字典
- matlab - 我正在尝试在 Matlab 中模拟蒙蒂霍尔问题。我究竟做错了什么?
- powerbi - 总结 Power BI 中串联列(或多列)的条形图
- office365 - 确定与office365的连接是否有效,如果没有连接,则执行某些操作
- html - 导航栏没有使我的链接居中,我不知道如何使用 flexbox
- c# - 建立与 SQL GRAPH API ADO 的连接时发生与网络相关或特定于实例的错误
- python - 返回 None 而不是 False
- google-apps-script - Google 表单中的可填写表格,用于记录特定 Google 表格中的数据
- intellij-idea - 运行 Java 11.02 JavaFX .jar 应用程序会产生奇怪的输出
- c++ - 如何使用快速排序对二维双打向量进行排序?