我正在使用日期范圍選擇器,讓我的用戶設定他們將從 Firestore 查詢的資料的日期范圍。我已經可以獲取日期范圍選擇器的值并將其從變數中存盤。我的問題是我不知道如何查詢 firestore 參考時間戳。
這是我從 Firestore 集合中查詢檔案的功能。到目前為止,我只能收集所有資料,但無法收集過濾資料(按時間戳)。
export async function Getfs(){
console.log("Get firestore run >>");
var f = document.getElementById("firstDate").value; // starting date
var s = document.getElementById("secondDate").value; // ending date
const fs_snap = await getDocs(query(collection(fs, "sens02"),orderBy('ts')));
}
這就是我的 Firestore 檔案的樣子
這就是我使用 html 輸入日期 范圍選擇器設計日期范圍選擇器的方式
uj5u.com熱心網友回復:
您需要使用Timestamp類的方法。
更準確地說,在您的情況下,您需要使用fromDate()以下示例中所示的:
const q = query(
collection(fs, "sens02"),
where('ts', '>=', Timestamp.fromDate(new Date('2022-05-28'))) // For example we use the 28/05/2002
);
const querySnapshot = await getDocs(q);
querySnapshot.forEach((doc) => {
console.log(doc.data().ts.toDate());
});
轉載請註明出處,本文鏈接:https://www.uj5u.com/ruanti/482674.html
標籤:javascript html 反应 火力基地 谷歌云火库
上一篇:如果沒有資料來,div不應該出現
