正在处理需要在日历上进行用户选择的应用程序。我正在选择日期范围并将其添加到数组中。数组存储在日期中。我在将阵列上传到Firestore时遇到问题。上传this.state.markedDates时,我不断收到错误消息。
第一个函数获取日期范围
getDates(s, e){
//below code is getting start date and end date plus placing the range in an array for upload into firebase.
var grabDates = [];
const start = moment(s).format("MM-DD-YYYY")
const end = moment(e).format("MM-DD-YYYY")
const range = moment.range(s, e)
const arrayOfDates = Array.from(range.by('days'))
arrayOfDates.map(m => {
var dates = m.format("YYYY-MM-DD");
grabDates.push(dates);
});
this.markedDates = grabDates
}
然后,我使用以下功能上传到Firebase。
confirm(){
if (this.markedDates == null){
alert('Please choose your dates');
} else {
var currentUser = firebase.auth().currentUser.uid;
var db = firebase.firestore();
var newData = db.collection('Calendars').doc(currentUser).collection('Dates');
newData.add({
bookedDates: [this.state.markedDates]
}).then(function(docRef){
console.log(docRef);
}).catch(function(error) {
console.log("Error writing document: ", error);
});
}
}
预先感谢您的帮助!