【发布时间】:2017-11-26 08:28:03
【问题描述】:
目前,我正在生成表头和行,但我想让行更加动态。如何在不重复多次的情况下打印行的数据?我怎样才能像标题一样使用 1 语句来做到这一点?所以基本上我只会调用'{row}',它应该生成行包含的所有内容,而不必输入'{row.school}'等......
const schoolData = [
{ school : 'Middle School', year : '2017', date : '6/12/17', location :
'Class',},
{ school : 'High School', year : '2017', date : '2/24/17', location :
'Gym',},
];
export default class Table extends Component {
render() {
const headers = Object.keys(schoolData[0]).map(header =>
<TableHeaderColumn>{header}</TableHeaderColumn>);
return (
<Tabs>
<Tab label="School Type">
<Table>
<TableHeader>
<TableRow>
{header}
</TableRow>
</TableHeader>
<TableBody>
{schoolData.map( (row) => (
<TableRow>
<TableRowColumn>{row.school}</TableRowColumn>
<TableRowColumn>{row.year}</TableRowColumn>
<TableRowColumn>{row.date}</TableRowColumn>
<TableRowColumn>{row.location}</TableRowColumn>
</TableRow>
))}
</TableBody>
</Table>
【问题讨论】:
-
发布
TableRow组件的代码。您可能会做的是修改该类,以便您可以简单地向它传递一个“行”对象并在内部构造自己的TableRowColumns。 -
上面没有代码
标签: javascript node.js reactjs iteration