antd Table组件的数据源必须用"key"属性?

antd Table组件的数据源必须用"key"属性?
使用中发现"key"是mysql的保留字,很不方便啊?

const dataSource = [{
  key: '1',
  name: '胡彦斌',
  age: 32,
  address: '西湖区湖底公园1号'
}, {
  key: '2',
  name: '胡彦祖',
  age: 42,
  address: '西湖区湖底公园1号'
}];

Warning: Each record in table should have a unique key prop,or set rowKey to an unique primary key.
哦 设置一下就好...

<Table columns={columns} dataSource={data} rowKey="id" />
阅读 27.5k
4 个回答
rowKey    : record => record.dataIndex,

或者

rowKey   : (record,index)=> index

可以给你的数据定一个dataIndex之类的值,最后会赋值到react的元素key上

rowKey={(r,i)=>(i)}

可以不用key 改成别的就行 数据库保留字段可以用 ``包裹设置

我的也是数据不唯一,

    <Table style={{ marginTop: 20 }} columns={clientColumns} dataSource={logItems} rowKey={(record, index) => index} pagination={false} bordered scroll={{ x: true }} />

我是这样解决的。

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进