2

我正在尝试使用 facebooks 的固定数据表来实现动态填充的数据列。我收到的数据列的范围从 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}
  />
  )
    }
})}

它不起作用。有没有人尝试过这样的事情?任何帮助将不胜感激。先感谢您。

4

1 回答 1

4

有效的是,用 map 替换 forEach。谢谢@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}
  />
  )
    }
})}

于 2016-03-28T17:51:13.563 回答