简体   繁体   中英

How can I retrieve data from many child in firebase database

I was trying to retrieve data from firebase. I can retrieve data from a single child. But how can I retrieve data from many child?

在此处输入图片说明

I tried this way

    func fatchSchdual(){
        ref.child("Products").child(productdetailes[myIndex].userId!).child("Schedule").child("0").observeSingleEvent(of: .value) { (snapshot) in

            if snapshot.childrenCount > 0{

                for Schdu in snapshot.children.allObjects as! [DataSnapshot]{
                    let schdual = Schdu.value as? [String: AnyObject]
                    let startTime = schdual?["start"]
                    let endTime = schdual?["end"]

                    if let StartTime = startTime{
                        self.publishTime.text = StartTime as? String
                    }




                }
            }
        }
    }

but I didn't get any data.

func fatchFacilities(){
    ref.child("Products").child(productdetailes[myIndex].userId!).child("Facility").observeSingleEvent(of: .value) { snapshot in

        for child in snapshot.children {
            if let value = (child as! DataSnapshot).value as? [String : Any] {
                let name = value["name"] as? String
                let unit = value["unit"] as? String
                let facility = Facility(name: name, unit: unit)
                facilities.append(facility)
            }
        }
    }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM