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.