快速访问嵌套的Firebase数据

编程入门 行业动态 更新时间:2024-10-26 21:23:51
本文介绍了快速访问嵌套的Firebase数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正在使用数据结构,并且正在遍历几个节点,这是我得到的json数据.

I am working wth a data structure, and I am looping through a couple nodes and here is the json data I get.

Snap (20171012) { "-KwM45HyW4UduQgKTGn6" = { ImageName = "Screen Shot 2017-10-13 at 11.24.51 AM.png"; fileURL = ""; thumbFileUrl = ""; user = "User not defined"; }; "-KwM4limD2aRyHgeKE5P" = { ImageName = "test.png"; fileURL = ""; thumbFileUrl = ""; user = "User not defined"; };

}

之后,我可以使用data.key访问"snap"值以获取"20171012"

After this, I can access the "snap" value using my data.key to get the "20171012"

ref.child(myselected_spot!).observe(DataEventType.value, with: { (snapshot) in if snapshot.childrenCount > 0 { for mydata in snapshot.children.allObjects as! [DataSnapshot] { if mydata.key.characters.count == 8 { self.formattedDates.append(convertDate(stringDate: mydata.key)) self.selected_dates.append(mydata.key)

如何获取"ImageName"的值

How would I get the value for "ImageName"

推荐答案

您的 mydata 是另一个 DataSnapshot ,因此您可以访问该类的所有方法和属性.在这种情况下,您要查找 DataSnapshot.childSnapshotForPath::

Your mydata is another DataSnapshot, so you can access all methods and properties of that class. In this case you're looking for DataSnapshot.childSnapshotForPath::

ref.child(myselected_spot!).observe(DataEventType.value, with: { (snapshot) in if snapshot.childrenCount > 0 { for mydata in snapshot.children.allObjects as! [DataSnapshot] { if mydata.key.characters.count == 8 { self.formattedDates.append(convertDate(stringDate: mydata.key)) self.selected_dates.append(mydata.key) print(mydata.childSnapshot(forPath: "ImageName").value)

更多推荐

快速访问嵌套的Firebase数据

本文发布于:2023-11-26 04:43:05,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1632669.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:嵌套   快速   数据   Firebase

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!