【发布时间】:2020-07-10 11:26:03
【问题描述】:
从 Firestore 获取数据并将其推送到数组中。这工作正常,但在此过程中,我正在更改时间戳格式,我希望在我的数组中而不是原始数组中的 timestamp 值。如何从原始值替换此值并推送?
到目前为止我的代码:
home.ts
firebase.firestore().collection("dailyreport").where("timestamp", ">=", start)
.onSnapshot(querySnapshot => {
var cities = [];
querySnapshot.forEach( doc=> {
const timeinmillsecs = doc.data().timestamp.seconds * 1000;
let a1 = new Date(timeinmillsecs);
let show_year_month_date = a1.getFullYear()+'/'+(a1.getMonth()+1) +'/'+a1.getDate(); // 3.convert to imple date
console.log(show_year_month_date); // ***NEED THIS VALUE IN dailyreports ARRAY
this.dailyreports.push(doc.data());
console.log("Timestamp greather than 29march -- ", (doc.data()));
});
});
console.log(doc.data())的截图
编辑 1
在推送之前,我已经分配了这样的值-
doc.data().timestamp = show_year_month_date;
this.dailyreports.push(doc.data());
但它也不起作用。
编辑 2
dailyreports 和doc 的截图:
【问题讨论】:
-
您要更改
this.dailyreports数组还是data.doc()? -
this.dailyreports 应该有一个新字段或当前时间戳字段应该更改为所需的格式
标签: angular typescript ionic-framework google-cloud-firestore ionic3