本机,我曾经尝试过使用await和.then,但是当我运行代码时,它将直接跳转到dispatch(successGetPostList)
userRef = firestore.collection('user')
const postList = []
await Promise.all(user.userFollowing.map(async (val) => {
postRef = firestore.collection('post').where('postOwner', '==', firestore.collection('user').doc(val))
await postRef.onSnapshot(async (collection) => {
await Promise.all(collection._docs.map(async (doc) => {
let post =doc.data()
await post.postOwner.get().then((user)=>{
let owner={
...user.data()
}
post ={
...post,
postId:doc.id,
owner:owner
}
postList.push(post)
})
}))
})
}))
dispatch(_successGetPostList(postList))