为什么id未定义?

时间:2021-02-28 11:20:37

标签: reactjs firebase google-cloud-firestore

我想获取文档的 id,但是当我在 console.log 时却没有定义 有没有办法同时包含文档 ID?

    this.unsubscribe = FirestoreService.getMessagesSnapshot(selected.id, selected.userId).onSnapshot((querySnapshot) => {
        if(querySnapshot.size > 0) {
            let tempObject = [];
            querySnapshot.forEach((doc) => {
               
                tempObject.push({
                    **id:doc.id,**
                    chatId: doc.data().chatId,
                    membersId: doc.data().membersId,
                    name: selected.name,
                    picRatio: doc.data().picRatio,
                    picUrl: doc.data().picUrl,
                    fileUrl: doc.data().fileUrl,
                    senderId: doc.data().senderId,
                    text: doc.data().text,
                    thumbUrl: doc.data().thumbUrl,
                    time: doc.data().time.toDate(),
                    videoUrl: doc.data().videoUrl,
                });
            });

0 个答案:

没有答案