Skip to content

Table组件,当dataSource的值出现相同的rowKey,数据展示不正确 #15261

@kstar11

Description

@kstar11
  • I have searched the issues of this repository and believe that this is not a duplicate.

Reproduction link

Edit on CodeSandbox

Steps to reproduce

1.为Table指定column和rowKey;
2.特意写几条rowKey相同的数据存放至dataSource;
3.使用this.setState改变dataSource;
4.发现rowKey相同的数据还存在表格中,只有最后一个rowKey相同的数据被干掉了(张六那条数据);

What is expected?

1.dataSource已经被重新赋值,应当展示重新赋值后的数据;

What is actually happening?

原来id重复的数据,不会被丢弃,dataSource中其实并不存在了

Environment Info
antd 3.14.1
React 16.8.3
System windows 10
Browser Chrome 72.0

这大约不算bug,讲道理,rowKey的要求就是非重复的,然而在实际业务中,偶尔会有数据出现重复的情况,这个点,颇为无奈
目前的馊招:
1.去掉rowKey,不指定rowKey,只是页面会抛错误,但是实际上并不影响使用.....2333
2.进行数组的去重比较(但是因为业务方面的问题,又得跟后台的小伙伴扯皮了...)
最后一个rowKey相同的数据会正确的丢掉,所以,是循环的时候出了问题???

Activity

yesmeck

yesmeck commented on Mar 7, 2019

@yesmeck
Member

确实不算 bug, key 必须唯一,React 的规矩我们也没什么好做的。

hygxmm

hygxmm commented on Jun 27, 2023

@hygxmm

对数据进行排序,两次返回的数据有相同的,dataSource里面数据正常,table会渲染两条一样的数据

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @yesmeck@yutingzhao1991@hygxmm@kstar11

        Issue actions

          Table组件,当dataSource的值出现相同的rowKey,数据展示不正确 · Issue #15261 · ant-design/ant-design