0

I've basically got rooms and sub rooms

rooms
   Room1:
     subroom 1 : true
     subroomABC: true
   Room2: 
     BobRoom: true
     CatRoom: true
     HatRoom: true

I'm basically just needing to pull the names (bobRoom/catroom/hatroom/subrooms) from each of the rooms and display them in a tableview.

I feel like normally I'd do something like getting the value and then do something like

snapshot.value["roomname]

to get info from something like this. Like posts are going to have a UID and all of the same key values like text/imageurl/poster, but here the keys are all different.

How do I grab the values under Room1 and Room2? I don't need them split up or anything, just a straight up list of all of the names.

I understand how to run observers and all of that and break snapshots down into snaps. I just can't wrap my head around this for some reason.

Thanks in advance for any help

J.Doe
  • 377
  • 3
  • 15
  • You'll need to loop over the children of the `rooms` snapshot. See http://stackoverflow.com/questions/37606236/how-do-i-loop-through-and-get-all-the-keys-of-the-nested-nodes-in-firebase/37606379#37606379 – Frank van Puffelen Aug 27 '16 at 04:29

1 Answers1

1

Maybe you can do like a query inside a query. I mean you can observe all the rooms with ref.child("Rooms") and observe events of type child added. Inside of the completion, you make another reference to the room. So for the first snapshot, it will be ref.child("Rooms").child(snapshot.key). Snapshot.key will give you room1 in this case. Then observe events of type value or child added for this new reference. You can get the names of the subrooms with snapshot.key again. I didn't try it out, but I think that should work. Maybe there is also a better way.

beginner_T
  • 417
  • 1
  • 6
  • 21