且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

从Firestore检索多个文档中的数据

更新时间:2023-02-14 08:48:56

快照对象包含集合中的所有3个文档.您必须遍历所有内容并将数据呈现到HTML,如下所述.

The snapshot object contains all the 3 documents in your collection. You must iterate over all and render data to your HTML as explained below.

db.collection("Policies List").get().then((snapshot) => {
  const documents = snapshot.docs //array of documents
  documents.forEach((doc) => {
    const docData = doc.data() //Data of that single document
    console.log(docData)
    renderToHtml() // Code that creates new HTML elements
  })
})

通过这种方式,您可以为集合中的所有文档创建新的HTML元素. renderToHtml()函数将包含该 .innerHTML 代码.请确保在控制台中查看日志.他们将帮助您更好地了解结构.

This way you are creating new HTML elements for all the documents in your collection. The renderToHtml() function will contain that .innerHTML code. Please make sure to see the logs in the console. They'll help understand the structure in a better way.