简体   繁体   English

如何从Firebase数据库中的许多子项中检索数据

[英]How can I retrieve data from many child in firebase database

I was trying to retrieve data from firebase. 我正在尝试从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)
            }
        }
    }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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