【发布时间】:2018-07-25 01:02:15
【问题描述】:
我将一个对象数组作为道具传递给我的 Table 组件,它应该将数组中的每个项目转换为表中的一行。但它没有输出任何东西......
我已经使用console.log 成功查看了数组中的每个项目。这是我的代码:
import React from 'react';
export default class Table extends React.Component {
getTableRow(x) {
console.log(x);
return ( <tr>
<td>{x.prop1}</td>
<td>{x.prop2}</td>
<td>{x.prop3}</td>
</tr>);
}
resolveInput() {
//expecting array
const array = this.props.lastFiveList;
//array.map(x => console.log(x));
array.map(x => this.getTableRow(x));
}
render() {
return (
<table>
{this.resolveInput()}
</table>
);
}
}
我还尝试绑定这两个函数(结果相同)并将 getTableRow 应该返回的内容放入变量中,然后返回变量而不是多行 return(); 语句。此外,我尝试使用forEach 而不是map。
【问题讨论】:
标签: javascript html reactjs jsx