[英]How to fix “Uncaught TypeError: Cannot read property 'Timestamp' of undefined”?
Hi I'm new in web development and I'm trying to make a firebase app with the firestore database. 嗨,我是Web开发的新手,我正在尝试使用Firestore数据库制作一个Firebase应用程序。 I have a user registration form and in this form I need to get the date. 我有一个用户注册表格,需要填写该表格的日期。 For the date I used datepicker but I can't get the selected date and after transform it into firestore Timestamp. 对于日期,我使用了日期选择器,但无法获取所选日期,并将其转换为Firestore时间戳后。 I tried this but I don't know if something is correct: 我尝试了这个,但是我不知道是否正确:
Html form: HTML形式:
<input class="datepicker" type="text" id="subscriptionDeadline" placeholder="Subscription Deadline">
Javascript code: JavaScript代码:
var currentDate = $(".subscriptionDeadline").datepicker("getDate");
var timeStamp = new firebase.firestore.Timestamp.fromDate(currentDate);
I get this error : 我收到此错误:
Uncaught TypeError: Cannot read property 'Timestamp' of undefined 未捕获的TypeError:无法读取未定义的属性“ Timestamp”
Your error is Cannot read property 'Timestamp' of undefined
. 您的错误是Cannot read property 'Timestamp' of undefined
。 In the code, it is trying to access firebase.firestore.Timestamp
. 在代码中,它正在尝试访问firebase.firestore.Timestamp
。
The error is saying that whatever you are trying to read the property Timestamp
from, is undefined. 该错误表明您尝试从中读取属性Timestamp
任何内容都是未定义的。 In your case it is firebase.firestore
. 在您的情况下,它是firebase.firestore
。 If you do a console.log(firebase.firestore)
it will show undefined, which means you won't be able to access the Timestamp property or anything else. 如果执行console.log(firebase.firestore)
,它将显示未定义,这意味着您将无法访问Timestamp属性或其他任何属性。
It sounds like the problem is you haven't initialized firestore properly on your page. 听起来问题是您尚未在页面上正确初始化firestore。 Make sure you have followed these steps: https://cloud.google.com/firestore/docs/quickstart-mobile-web#set_up_your_development_environment 确保您已按照以下步骤操作: https : //cloud.google.com/firestore/docs/quickstart-mobile-web#set_up_your_development_environment
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.