【发布时间】:2017-12-10 07:41:11
【问题描述】:
我试图从一个孩子那里得到一个特定的价值,然后从另一个孩子那里得到其余的。这就是我的数据库的样子。我想从Bienmesabe 的键longDescription put 中获取值。
func getCakeDescription (from category: String, subcategory: String, handler: @escaping (_ cakeDescription: [GeneralInfo]) -> ()) {
var cakeDescriptionArray = [GeneralInfo]()
let trimCategory = category.trimmingCharacters(in: .whitespaces)
let trimSubcategory = subcategory.replacingOccurrences(of: " ", with: "")
REF_CAKES.child(trimCategory).child(trimSubcategory).observeSingleEvent(of: .value) { (returnedDescriptionSnapshot) in
guard let returnedDescriptionSnapshot = returnedDescriptionSnapshot.children.allObjects as? [DataSnapshot] else {return}
for cakesDesc in returnedDescriptionSnapshot{
let cakeLongDescription = cakesDesc.childSnapshot(forPath: "longDescription").value as! String
self.REF_CAKES.child("General").observeSingleEvent(of: .value) { (returnedGeneralSnapshot) in
guard let returnedGeneralSnapshot = returnedGeneralSnapshot.children.allObjects as? [DataSnapshot] else {return}
for generalInfo in returnedGeneralSnapshot{
let titleDelivery = generalInfo.childSnapshot(forPath: "TitleDelivery").value as! String
let orderAndDelivery = generalInfo.childSnapshot(forPath: "OrderAndDelivery").value as! String
let titleSizeAndPrice = generalInfo.childSnapshot(forPath: "TitleSizeAndPrice").value as! String
let sizeAndPrice = generalInfo.childSnapshot(forPath: "SizeAndPrice").value as! String
let titlePromo = generalInfo.childSnapshot(forPath: "TitlePromo").value as! String
let promotions = generalInfo.childSnapshot(forPath: "Promotions").value as! String
let cakesInfo = GeneralInfo(titleDevilery: titleDelivery, titleSizeAndPrice: orderAndDelivery, titlePromo: titleSizeAndPrice, sizeAndDelivery: sizeAndPrice, orderAndDelivery: titlePromo, promotions: promotions, cakeDescription: cakeLongDescription)
cakeDescriptionArray.append(cakesInfo)
}
}
}
handler(cakeDescriptionArray)
}
}
【问题讨论】: