检索时对象立即消失

时间:2019-05-05 06:23:48

标签: reactjs react-redux google-cloud-firestore

以下是从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;

0 个答案:

没有答案