我正在开发一个使用 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-50cituc-28db-459tb-e886-417b547- b5405d902072 ":25.197669830084113,"longitude":46.33913576602936,"storename":"3023b667-3cb2-400e-8a36-1113be9e816c","title":"111"nfk0fk8rfk0fk8rfk8rfk8rg0z"8
使用 snap.child.val() 我能够从描述、经度、纬度等中检索数据,但无法检索 imageUrls...因为它包含 child 或其数组。如何从 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
})
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句