简体   繁体   English

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

[英]Unable to retrieve data from Multiple collection firebase

Hope you're in good health.希望你身体健康。 I have a problem.我有个问题。

 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)); } ); }; }

I am Unable to get address in state but when I log it It displayed in console.我无法在 state 中获取地址,但是当我记录它时它显示在控制台中。 I am able to access address when I am retrieving it from firebase and also in reducer I am also getting address.当我从 firebase 检索地址时,我能够访问地址,并且在减速器中我也得到地址。

reasons can be: The hierarchy of your firestore collection or you have to know that in js you can't affect the data to a variable that is in the main prog just when it is in a one level functions for exemple here you can do this原因可能是:您的 Firestore 集合的层次结构,或者您必须知道在 js 中,您不能将数据影响到主编中的变量,仅当它位于一级函数中时,例如这里您可以这样做

locale = this ;

than you can use all the variables in two other levels比你可以使用其他两个级别的所有变量

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM