Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

table组件会给传给dataSource的数组里的每一项增加indexForSort属性 #2501

Closed
vxzhong opened this issue Jul 26, 2016 · 5 comments

Comments

@vxzhong
Copy link
Contributor

vxzhong commented Jul 26, 2016

本地环境

  • antd 版本: 1.6.5
  • 操作系统及其版本:osx 1.11.6
  • 浏览器及其版本: chrome

你做了什么?

创建了一个table:

<Table
      loading={loading}
      columns={columns}
      dataSource={data}
    />

你期待的结果是:

table组件不改变dataSource的值,即data不变。

实际上的结果:

data数组里的每一项多了一个indexForSort的属性。

看了一下table的代码,做了数组本身的拷贝,但直接修改了每一项,能不能用{ ...data[i], indexForSort: i }代替?

var data = this.props.dataSource || [];
    // 优化本地排序
    data = data.slice(0);
    for (var i = 0; i < data.length; i++) {
      data[i].indexForSort = i;
    }

可重现的在线演示

@afc163
Copy link
Member

afc163 commented Jul 26, 2016

👍 来个 PR 吧 ~

发到 1.x-stable 分支。

@Ben07
Copy link

Ben07 commented Aug 17, 2016

1.9.1版本中依然存在此indexForSort的属性。
能否去掉?

@benjycui
Copy link
Contributor

存在是对的,原来的问题是修改了数据源。

@Ben07
Copy link

Ben07 commented Aug 17, 2016

@benjycui 我原本通过record拿到一条数据,修改后直接提交就是了,现在得手动delete这个indexForSort属性。觉得别扭

@lock
Copy link

lock bot commented May 4, 2018

This thread has been automatically locked because it has not had recent activity. Please open a new issue for related bugs and link to relevant comments in this thread.

@lock lock bot locked as resolved and limited conversation to collaborators May 4, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants