![](/img/trans.png)
[英]Getting an Error on console while saving data in firebase firestore
[英]Getting data not defined error while accessing data from Firebase Firestore
我有帶有 4 個文檔的 Collection 命名產品。
我正在嘗試訪問數據並將其寫入文檔或將其記錄到控制台。
但是我不斷收到以下錯誤
app-min.js:1 Uncaught (in promise) ReferenceError: data is not defined
這是我的代碼
document.addEventListener("DOMContentLoaded", even => {
const app = firebase.app();
const db = firebase.firestore();
const productsRef = db.collection('products');
const query = productsRef.orderBy('price', 'desc')
query.get()
.then(products => {
products.forEach(doc => {
data = doc.data();
document.write(`${data.name} at $${data.price} <br>`);
console.log(data);
})
})
});
不太確定從這里去哪里,任何幫助表示贊賞。
嘗試將 let 放在這樣的數據之前:
讓數據 = doc.data()
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.