我有以下子数据:
Jeans
gender: "female"
imageOfClothes: "url"
name: "Jeans"
price: "1999"
type: "clothes"
我想在tableView
上显示以下参数:性别-女性,类型:衣服。
我的查询如下:
let ref = Database.database().reference().child("Clothes/")
let query = Ref.queryOrdered(byChild: "gender").queryEqual(toValue: "male")
query.observe(.value) { (snapshot) in
var tempClothes = [Clothes]()
for child in snapshot.children {
if let childSnapshot = child as? DataSnapshot,
let dict = childSnapshot.value as? [String:Any],
let name = dict["name"] as? String,
let gender = dict["gender"] as? String,
let price = dict["price"] as? Int,
let type = dict["type"] as? String,
let imageOfClothes = dict["imageOfClothes"] as? String,
let url = URL(string: imageOfClothes) {
let clothes = Clothes(name: name, price: price, imageOfClothes: url, gender: gender, type: type)
tempClothes.append(clothes)
print(tempClothes)
}
}
我不知道如何使用多个查询。 这是行不通的:
let query = ref.queryOrdered(byChild: "type").queryEqual(toValue: "clothes").queryOrdered(byChild: "gender").queryEqual(toValue: "female")