我正在开发一个使用 firebase 的 React Native 应用程序。当我从 firebase 获取数据时,我得到了这样的数据快照
{"674cafe2-e886-4d9d-b547-b5405d902072":{"description":"111","imageUrls":{"0":"https://firebasestorage.googleapis.com/v0/b/aam-623b6.appspot.com/o/flyers%2F674cafe2-e886-4d9d-b547-b5405d902072%2F2.jpg?alt=media&token=c56cc053-7167-44eb-9f8b-fb55664eacac","1":"https://firebasestorage.googleapis.com/v0/b/aam-623b6.appspot.com/o/flyers%2F674cafe2-e886-4d9d-b547-b5405d902072%2F1.jpg?alt=media&token=f1693b41-28db-4129-a5c7-190b96656e5b"},"latitutde":25.197669830084113,"longitude":46.33913576602936,"storename":"3023b667-3cb2-400e-8a36-1113be9e816c","title":"111","user":"8Igfk0bT06MOkzrP8Y5njOdfi0k2"}}
使用 snap.child.val() 我能够从描述、经度、纬度等检索数据,但无法检索 imageUrls...因为它包含子项或其数组。如何从 imageUrls 中检索第一个子元素
最佳答案
下面是获取imageUrls
的代码:
firebase.database().ref(YOUR_PATH).on('value', snap => {
if (snap.exists()) {
let stringifyObject = JSON.stringify(snap)
let obj = JSON.parse(stringifyObject);
obj.key = snap.key
console.log(JSON.stringify(obj.imageUrls)) // This will print your array and you do work around it
})
关于javascript - 如何从 Firebase 数据快照中检索数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55620714/