以下是从Firestore检索数据的代码,但它仅显示了数组中的第一个对象。下一个对象立即消失。
var joblists = []
const allChatList = (task) => {
return (dispatch, getState, { getFirebase, getFirestore }) => {
const firestore = getFirestore();
joblists = []
firestore.collection("Jobs")
.get()
.then(function (querySnapshot) {
querySnapshot.forEach(function (doc) {
firestore.collection("Chat").doc(doc.id).collection('Interaction').where("sentto", "==", task)
.get()
.then(function (querySnapshot) {
querySnapshot.forEach(function (doc1) {
joblists.push({ ...doc.data() })
});
}).then(() => {
console.log("joblists ", joblists);
dispatch({ type: 'ALL_CHAT_JOB', payload: joblists })
})
.catch(function (error) {
console.log("No record: ", error);
});
});
})
.catch(function (error) {
console.log("Error getting documents: ", error);
});
}
}
export default allChatList;