【发布时间】:2021-12-15 12:40:44
【问题描述】:
这个问题与这个问题有关:Get documents names in Firestore 但我还不能发表评论。
我正在尝试从我的 FireStore 中获取一个嵌套对象,看起来像这样
{"docname1": {…}, "docname2": {…}, "docname3": {…}}
我现在有了这个,但似乎无法弄清楚如何创建嵌套对象以将其推送到空数组中。
useEffect(() => {
const getPlants = async () => {
let response = []
const querySnapshot = await firebase
.firestore()
.collection('plants')
.get()
querySnapshot.forEach((doc) => {
let newObject = [doc.id: doc.data() ]
response.push(newObject)
})
setPlants(response)
}
getPlants()
}, [])
非常感谢任何帮助:)
【问题讨论】:
标签: javascript arrays reactjs firebase google-cloud-firestore