题意:如何解决“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. 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. I tried this but I don't know if something is correct:
嗨,我是网页设计的新手,我正在尝试使用 Firestore 数据库制作一个 Firebase 应用。我有一个用户注册表单,在这个表单中我需要获取日期。对于日期,我使用了日期选择器,但是我无法获取选中的日期并将其转换为 Firestore 的 Timestamp。我尝试过这样做,但我不知道是否正确:
Html form:
<input class="datepicker" type="text" id="subscriptionDeadline" placeholder="Subscription Deadline">
Javascript code: js代码
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
问题解决:
Your error is Cannot read property 'Timestamp' of undefined
. In the code, it is trying to access firebase.firestore.Timestamp
.
你的错误是“Cannot read property 'Timestamp' of undefined”,在代码中,它试图访问 firebase.firestore.Timestamp
The error is saying that whatever you are trying to read the property Timestamp
from, is undefined. In your case it is 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.
错误表明,你尝试从中读取属性 Timestamp
的对象是未定义的。在你的情况下,这个对象是 firebase.firestore
。如果你执行 console.log(firebase.firestore)
,它将显示 undefined
,这意味着你将无法访问 Timestamp
属性或任何其他属性。
It sounds like the problem is you haven't initialized firestore properly on your page. Make sure you have followed these steps: 听起来问题是你还没有在页面上正确初始化 Firestore。请确保你按照以下步骤操作:https://cloud.google.com/firestore/docs/quickstart-mobile-web#set_up_your_development_environment