在Firebase Firestore中映射集合快照的项目 [英] Map items of collection snapshot in Firebase Firestore

查看:69
本文介绍了在Firebase Firestore中映射集合快照的项目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Firebase Firestore指南显示如何使用 forEach 遍历集合快照中的文档:

Firebase Firestore Guides show how to iterate documents in a collection snapshot with forEach:

db.collection("cities").get().then(function(querySnapshot) {
    querySnapshot.forEach(function(doc) {
        console.log(doc.id, " => ", doc.data());
    });
});

我想它也会支持 map ,但事实并非如此。如何映射快照?

I imagined it would support map as well, but it doesn't. How can I map the snapshot?

推荐答案

答案是:

querySnapshot.docs.map(function(doc) {
  # do something
})

Firestore的参考页面显示快照上的 docs 属性。


docs 非空firebase.firestore.DocumentSnapshot的非空数组

QuerySnapshot中的所有文档。

An array of all the documents in the QuerySnapshot.

这篇关于在Firebase Firestore中映射集合快照的项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆