使用antd的table时出现警告: Each record in table should have a unique `key` prop,or set `rowKey` to an uniq

ant design 专栏收录该内容
2 篇文章 0 订阅

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:

意思就是:这个报错是说需要对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.

  • 0
    点赞
  • 0
    评论
  • 0
    收藏
  • 一键三连
    一键三连
  • 扫一扫,分享海报

©️2021 CSDN 皮肤主题: 大白 设计师:CSDN官方博客 返回首页
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值