Warning: Each record in table should have a unique `key` prop,or set `rowKey` to an unique primary k

antd使用Table报错,

报错:Warning: Each record in table should have a unique `key` prop,or set `rowKey` to an unique primary key.

解决方法:

This one was confusing to me as well, because I was confusing COLUMN keys with ROW keys. This error has nothing to do with "key" in your column config.

Ant is expecting you to have a unique key specifically named "key" on each row of data, like so:

{ key: 1, value: 'foo'}

My data had "id" instead:

{ id: 1, value: 'foo'}

In order to resolve this, I added a rowKey property to my Table like so:

<Table columns={this.columns} dataSource={this.state.results} rowKey='id' />

https://github.com/ant-design/ant-design/issues/7623

意思就是:这个报错是说需要对dataSource的行加key,不是对列加key,同时这里的rowKey需要使用行的唯一的属性名,不能使用不唯一的属性名或不存在的属性名,不然还是报那个错。列是否加key均可。

如果使用不唯一的属性名作为行key,则报错如下:

Warning: Encountered two children with the same key, `XXX`. Keys should be unique so that components maintain their identity across updates.

如果使用不存在的属性名作为行key,则报错如下:

Warning: Each record in table should have a unique `key` prop,or set `rowKey` to an unique primary key.

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

二十六画生的博客

你的鼓励是我创作最大的动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值