Firestore: How to include doc.id in doc.data() while mapping?

前端 未结 1 522
野的像风
野的像风 2021-01-21 11:09

I want to bind my data to the below HTML table:

No.<
1条回答
  •  说谎
    说谎 (楼主)
    2021-01-21 11:51

    To get the doc.id you have to use snapshotChanges() in your code like this:

    db.collection("Accounts").snapshotChanges().map(actions => {
      return actions.map(a => {
        const data = a.payload.doc.data();
        const id = a.payload.doc.id;
        return { id, ...data };
      });
    });
    

    0 讨论(0)
提交回复
热议问题