我们如何使用Angular通过TimeStamp数据类型对Firebase Firestore数据进行排序? [英] How can we sort Firebase Firestore data by TimeStamp dataType using Angular?
问题描述
我正在使用票证发布Web应用程序,并且我将仅显示那些有效且具有24小时记录(从现在开始)的票证.
I am having Ticket Posting Web App, and i would show only those tickets which are active and with-in 24 hours records(from now on).
我正在将 Firebase Cloud Firestore 与 Angular 7 结合使用.
getTicketList(){
this.ticketData =
this.fireStore.collection('ticket').doc("paid").collection("ticket-list",
ref =>
ref.where('status', '==',
"active").where("paid","==","false").orderBy("myTimeStamp");
return this.ticketData.snapshotChanges() ;
}
我们有一个键"myTimestamp",它是 Firestore Timestamp 类型.
We are having a a key "myTimestamp" which is Firestore Timestamp Type.
只想显示那些有效且当前还有剩余时间要预定的记录.
want to show only those records which are active and currently having a time remaining to book.
下面我提到了我用来从Firebase服务获取的代码.
Beow i mentioned the codes which i am using to get from Firebase service.
this.firestore.getTicketList().subscribe(list => {
this.ticketList = list.map(item => {
return { id:item.payload.doc.id,
...item.payload.doc.data()}
})
console.log(this.ticketList);
});
谢谢
已编辑
推荐答案
您可以通过传递 Date
对象来查询数据/时间戳字段.因此,例如,现在就获取所有物品:
You can query on a data/timestamp field by passing a Date
object. So for example to get all items before right now:
ref
.where('status', '==', "active")
.where("paid","==","false")
.where("myTimeStamp","<", new Date())
.orderBy("myTimeStamp")
这篇关于我们如何使用Angular通过TimeStamp数据类型对Firebase Firestore数据进行排序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!