无法从多个集合firebase检索数据



希望你身体健康。我有个问题。

export function fetchListing() {
return function (dispatch) {
dispatch(fetchListingRequest());
//Getting Listing where status is in_review
firebase
.firestore()
.collection("listings")
.where("status", "==", "in_review")
.onSnapshot(
snapshot => {
const data = [];
snapshot.docs.forEach(doc => {
const temp = {};
// Getting address of business
firebase
.firestore()
.collection("users")
.doc(doc.data().business_id)
.get()
.then(users => {
temp["address"] = users.data().address;
})
.catch(error => {
dispatch(fetchListingFailed(error));
});
temp["title"] = doc.data().title;
temp["description"] = doc.data().description;
temp["listing_file"] = doc.data().listing_file;
data.push([doc.id, temp]);
});
dispatch(fetchListingSucess(data));
},
error => {
dispatch(fetchListingFailed(error));
}
);
};
}

我无法获取状态下的地址,但当我记录它时,它显示在控制台中。当我从firebase检索地址时,我可以访问地址,而且在reducer中我也可以获得地址。

原因可能是:消防仓库系列的层次结构或者你必须知道,在js中,你不能只在主程序中的一个变量处于一级函数中时就将数据影响到它举个例子,你可以做这个

locale = this ;

比你可以使用其他两个级别中的所有变量