2016-03-28 45 views
2

我想通过使用Facebook的固定数据表实现一个动态填充的数据列。我收到列数在10 - 100之间的数据。所以我的意图是动态创建列。下面是我曾尝试如何在固定数据表中添加动态列

Class App extensd React.Component{ 
 
    render(){ 
 
    return (
 
      <Table 
 
       rowHeight={50} 
 
       headerHeight={30} 
 
       groupHeaderHeight={30} 
 
       rowsCount={10} 
 
       width={tableWidth} 
 
       height={500} 
 
       {...this.props}> 
 
       
 
      {["firstName","lastName","bs","email"].forEach(function(columnName){ 
 
      return <Column 
 
        columnKey={columnName} 
 
        header={ <Cell>Header</Cell>} 
 
        cell={<Cell>Cell Content</Cell>} 
 
        width={200} 
 
    /> 
 
) 
 
    } 
 
})}

它不工作。有没有人曾经尝试过类似的东西?任何帮助将不胜感激。先谢谢你。

+0

你有拼写错误** **延伸。此外,如果内部有子组件,则打开的标签需要使用结束标签来关闭。 –

+3

除了拼写错误外,'forEach'方法不返回新数组;你需要使用'map'来代替。 –

+0

谢谢@JeffWooden。这真是愚蠢的我。 – dhiraj

回答

3

什么工作是,用地图代替每个。谢谢@ jeff-Wooden。

Class App extends React.Component{ 
 
    render(){ 
 
    return (
 
      <Table 
 
       rowHeight={50} 
 
       headerHeight={30} 
 
       groupHeaderHeight={30} 
 
       rowsCount={10} 
 
       width={tableWidth} 
 
       height={500} 
 
       {...this.props}> 
 
       
 
      {["firstName","lastName","bs","email"].map(function(columnName){ 
 
      return <Column 
 
        columnKey={columnName} 
 
        header={ <Cell>Header</Cell>} 
 
        cell={<Cell>Cell Content</Cell>} 
 
        width={200} 
 
    /> 
 
) 
 
    } 
 
})}