【发布时间】:2021-01-13 05:23:26
【问题描述】:
我正在尝试显示我的 firestore 集合中的时间戳值,但我收到此错误“TypeError: (intermediate value).toDate is not a function”,我在下面用“>>”标记。 我在将其提交到 Firestore 之前将其设置为时间戳,但现在要显示它,我需要将其作为日期值 你有什么解决办法吗?
componentDidMount() {
db.collection("mycollection")
.get()
.then(querySnapshot => {
const data = querySnapshot.docs.map(doc => doc.data());
this.setState({ costumers: data });
});
}
render(){
const { costumers } = this.state;
return (
<Card
>
<PerfectScrollbar>
<Box minWidth={1050}>
<Table >
<TableHead>
<TableRow>
<TableCell padding="checkbox">
</TableCell>
{costumers.map(costumer => (
<TableBody>
<TableRow
>
<TableCell padding="checkbox">
<Checkbox
value="true"
/>
</TableCell>
<TableCell>
<Box
alignItems="center"
display="flex"
>
<Typography
color="textPrimary"
variant="body1"
>
{costumer.name}
</Typography>
</Box>
</TableCell>
<TableCell>
{costumer.surname}
</TableCell>
<TableCell>
{costumer.email}
</TableCell>
<TableCell>
{costumer.phone}
</TableCell>
<TableCell>
>> {new Date(costumer.date).toDate()}
</TableCell>
<TableCell>
{costumer.time}
</TableCell>
<TableCell>
{costumer.service}
</TableCell>
</TableRow>
</TableBody>
))}
</Table>
【问题讨论】:
-
您是否尝试过 console.log 记录costumer.date 的值?您是否也在为穿着服装的人或客户制作应用程序? ;)
标签: json reactjs firebase google-cloud-firestore timestamp