簡體   English   中英

如何調用在firebase firestore中聲明的變量

[英]How to call a variable which is declared inside firebase firestore

我的 Firebase > Firestore > Collection > Document 中有一些值。 我可以通過以下方式訪問它們,

db.collection("Fund").doc("Status").get().then((doc)=>{

let MTBNAV = doc.data().SPMTB

}

現在,我想在函數外訪問我的 MTBNAV,而無需調用另一個函數並設置參數

使用 await 獲取 MTBNAV。 像這樣:

let MTBNAV = (await db.collection('Fund').doc('Status').get()).data().SPMTB

嘗試這個。

更容易理解的代碼應該是:

const myFunc = async () => {
  const collectionRef = db.collection("Fund")
  const doc = await collectionRef.doc("Status").get()
  let MTBNAV = doc.data().SPMTB
  }
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM