【发布时间】:2021-03-06 10:41:03
【问题描述】:
我有这些收藏:
- 具有名称和图像的用户(Uid = 文档),
- Post(Uid Post = doucment) 包括正文、图片和 Uid(Uid 用户)
我使用嵌套循环来拥有一个简单的对象(我不使用 2 个数组)
firebase.firestore().collection("Post").get()
.then(querySnapshot => {
querySnapshot.forEach(documentSnapshot => {
this.setState({
dataPost: this.state.dataPost.concat({
...documentSnapshot.data(),
key: documentSnapshot.id,
name: this.getUserbyUid(documentSnapshot.data().uid) <- get Name user as soon as I get the uid from the Post collection
}),
})
});
});
getUserbyUid = (Uid) => {
firebase.firestore().collection('user').doc(Uid).get()
.then(documentSnapshot => {
return documentSnapshot.data().name
})}
我收到一个错误name: Undefinded
这是我的想法,我知道有很多更好的方法请帮助我tks
发布
用户
Object {
"body": "hfdbdb"
"date": 1614903953253,
"image": “"https://firebasestorage.googleapis.com/v0/t.....-44¢5-b091-7af310de36d1",
"key": "IX9KKfcOONSyquUtossTd",
"name": undefined,
"uid": "Chc1P3zcWMguc2d2ppKSRrpQx752",
},
【问题讨论】:
标签: react-native google-cloud-firestore