javascript - 为什么我的 key 重复?

标签 javascript reactjs key fixed-data-table

这是我的渲染方法:

  render: function() {
    var rows = this.state.users;
     return (
        <div className="container">
            <dl className="row">
                <div className="col-md-12">
                    <Table
                        rowHeight={50}
                        rowsCount={rows.length}
                        width={800}
                        height={500}
                        headerHeight={50}>
                        <Column
                            header={<Cell>First Name</Cell>}
                            cell={(_.map(rows, function(row) {
                                return <Cell key={row.id}>{row.firstname}</Cell>;
                            }))}
                            width={200}
                        />
                    </Table>
                    <button type="button" onClick={this.formPopup}>Add User</button>
                </div>
            </dl>
        </div>
    );

为什么 View 仍然显示重复项? 这是完整代码的链接:https://github.com/DannyGarciaMartin/react-webpack/blob/master/js/source/comp/UserView.jsx

我不明白。我的映射不应该与固定数据表的输入呈现进行区分吗?

这是一张图片作为 key 不起作用的证据......

enter image description here

最佳答案

cell 属性应该是一个节点或函数,请参阅 this了解更多详情。

因此,将单元格更改为

cell={props => (
        <Cell {...props}>
          {rows[props.rowIndex].firstname}
        </Cell>
      )}

关于javascript - 为什么我的 key 重复?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42869424/

相关文章:

reactjs - 在 React 中用 404 图像替换损坏的图像

c++ - PostgreSQL主键自增在C++中崩溃

javascript - 当鼠标静止时使框淡出并在鼠标移动时淡入

javascript - 这行 typescript 是什么意思?

javascript - 如何让 forEach 循环等待每个 Ajax 函数完成

javascript - 从 child 更改 parent 的状态时,为什么 parent 不再渲染?

reactjs - 如何在功能组件中将输入值从子级传递到父级

ios - 使用选定键的 Parse.com 关系查询

linux - ZSH 绑定(bind)键反向查找

javascript - (My)SQL 上的正则表达式创建语句