2017-12-24 5 views
0

firebase에서 데이터를 검색하려고했습니다. 한 아이에게서 데이터를 검색 할 수 있습니다. 하지만 어떻게 많은 어린이로부터 데이터를 검색 할 수 있습니까? firebase 데이터베이스에있는 많은 하위에서 데이터를 검색하는 방법

enter image description here

나는이 방법

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 
        } 




       } 
      } 
     } 
    } 

을 시도하지만 난 어떤 데이터를 얻을하지 않았다.

답변

1
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) 
      } 
     } 
    } 
} 
관련 문제