我在 Firestore 中使用了一個檔案,該檔案存盤了三個具有布林值的欄位。我需要這個布林值進行進一步處理。在我的程式中,我想讀取這些值。但是如何讀取檔案的欄位呢?正如這里所解釋的,它應該像下面這樣作業:
const getStateEntries = async () => {
await getDoc(doc(db, 'Collection_Name', 'Document_ID'))
.then((docSnap)=> {
let alertField = docSnap.data['alert_state']
console.log(alertField)
})
setAlertState(alertField)
}
當我運行代碼時,似乎無法訪問該欄位。當我將變數列印到控制臺時,我得到一個'undefined'.
uj5u.com熱心網友回復:
該資料不是 DocumentSnapshot 上的屬性。嘗試重構代碼,如下所示:
let alertField = docSnap.data().alert_state
uj5u.com熱心網友回復:
你可以得到類似下面的代碼:
firestore()
.collection('Users')
.get()
.then(querySnapshot => {
console.log('Total users: ', querySnapshot.size);
querySnapshot.forEach(documentSnapshot => {
console.log('User ID: ', documentSnapshot.id, documentSnapshot.data());
});
});
供參考使用,這個:https ://rnfirebase.io/firestore/usage
希望對您有所幫助!
轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/457425.html
標籤:javascript 反应 反应式 谷歌云火库
上一篇:這條線存盤什么值charc=str[sizeof(int*)];?
下一篇:如何同時通過輸入和按鈕更改值
