2017-03-18 169 views
0

这里是我的渲染方法:为什么我的密钥复制?

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> 
    ); 

为什么认为仍呈现重复?这里是一个链接到完整的代码:https://github.com/DannyGarciaMartin/react-webpack/blob/master/js/source/comp/UserView.jsx

我不明白。我的映射不应该与输入为固定数据表呈现什么区别?

这里的作为证明的钥匙没有工作的图像...

enter image description here

回答

1

cell道具应该是一个节点或功能看到this了解更多详情。

所以,改变cell

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

你能解释一下道具=>(...)}确实/手段?这工作,谢谢。我认为传递_.map(...)是一个函数。所以我猜测“道具=> ...”是必需的。 – fungusanthrax

+1

_.map()正在调用一个函数,结果是一个Array。因此,'cell'的值是Array,而不是函数。在我的回答中,cell = function,在你的代码中cell = function()//调用一个函数.Column组件将根据rowCount,所以你不需要映射行数据。 – wuxiandiejia

相关问题