【发布时间】:2020-06-05 02:39:02
【问题描述】:
功能
checkIfSeen = (uid, news_id) => {
var seen = false;
const docRef = DB.informationsCollection.doc(news_id).collection('users').doc(uid);
docRef.get()
.then((docSnapshot) => {
if (docSnapshot.exists) {
seen = true;
console.log(seen);
// returns true
}
});
console.log(seen);
// returns false
}
问题
它在if (docSnapshot.exists) { 之后返回true,但在函数的最后一个返回false。
有人知道为什么会这样吗?
如果您能给我任何建议,我将不胜感激。
更新
checkIfSeen = (uid, news_id) => {
const docRef = Fire.shared.informationsCollection.doc(news_id).collection('users').doc(uid);
docRef.get()
.then((docSnapshot) => {
if (docSnapshot.exists) {
this.alreadySeen();
} else {
this.notSeen();
}
});
}
alreadySeen = () => {
return true;
}
notSeen = () => {
return false;
}
【问题讨论】:
标签: javascript reactjs react-native google-cloud-firestore