我显示信息的反应代码如下我的数据显示正确问题是日期没有正确显示日期显示为/日期(1533668400000)/数据库条目是2018-08-08 00:00 :00.000我添加了scrrenshots,因此很容易理解
class BorrowHistoryGridRow extends React.Component
{
constructor(props)
{
super(props);
this.state = {items:this.props.items}
}
render()
{
return (
<tr>
<td>{this.props.item.bName}</td>
<td>{this.props.item.cName}</td>
<td>{this.props.item.bhBorrowDate}</td>
<td>{this.props.item.bhReturnDate}</td>
</tr>
);
}
}
您可以调用一个可以解决显示问题的功能
<td>{this.getDate(this.props.item.bhBorrowDate)}</td>
并且该函数将返回您可以打印的格式化日期的字符串。
getDate = (x) => {
const a = x;
const b = Number(a.slice(6, a.length - 2));
const c = new Date(b);
return c.toLocaleDateString();
}
如果您不喜欢这种类型的数据格式,您可以轻松地使用其他原生JavaScript,或使用moment.js