【发布时间】:2020-02-06 15:58:05
【问题描述】:
如何使值在 onSnapshot 函数之外返回?
function checkIfExisting(){
const collection = firebase.firestore().collection("audit");
const getCaseID = collection.where("caseID", "==", "00001234");
getCaseID.onSnapshot(function(querySnapshot) {
let wordLists = [];
querySnapshot.forEach(function(doc) {
//get all the scanned words under "word" field in the Firestore Database
wordLists.push(doc.data().word);
});
console.log("words: ", wordLists);// return a value
});
console.log("words1: ", wordLists);// undefined
}
我知道console.log("words1: ", wordLists) 在函数之外,这就是我无法获得它的值的原因。您能否告诉我如何在函数之外调用它(如果可能)。
【问题讨论】:
标签: javascript firebase google-cloud-firestore