React native 从react native中的firestore集合获取值
我想编写一个函数来获取集合的值,如图所示: 这是我的代码,我真的不知道在“then()”之后该做什么:React native 从react native中的firestore集合获取值,react-native,google-cloud-firestore,snapshot,React Native,Google Cloud Firestore,Snapshot,我想编写一个函数来获取集合的值,如图所示: 这是我的代码,我真的不知道在“then()”之后该做什么: 注意currentUser是redux,这意味着查询将仅对登录的当前用户执行如果您想返回businessLocation的值,则只能执行以下操作: const getLocation = () => { return firebase.firestore() .collection("users") .doc(
注意currentUser是redux,这意味着查询将仅对登录的当前用户执行如果您想返回
businessLocation的值,则只能执行以下操作:
const getLocation = () => {
return firebase.firestore()
.collection("users")
.doc(currentUser.uid)
.get()
.then(function(doc) {
if (doc.exists) {
data = doc.data();
return data.businessDetails.businessLocation;
} else {
return "";
}
});
};
您可以在以下位置获得有关如何在firestore中获取数据的更多信息
注意:这使您的函数成为异步函数。因此,你应该这样称呼它:
getLocation().then(result => {
//Do whatever you want with the result value
console.log(result);
})
getLocation().then(result => {
//Do whatever you want with the result value
console.log(result);
})