我正在开发一个交付应用程序。所以我在 firebase 中有 productos 和流行的产品:
- 产品
- PopularProducts(产品 ID 作为键,true 作为值)
如何只查询使用这些 child 的热门产品?
最佳答案
您需要获取productos Populares
数组,然后获取每个对象。
let referenceToProductosPopulares = FIRDatabase.database().reference(withPath: "productosPopulares")
referenceToProductosPopulares.observeSingleEvent(of: .value, with: { snapshot in
if let value = snapshot.value as? NSDictionary {
let productosPopIds = value.allKeys as! [String]
// get every object
for id in productosPopIds {
let refToProd = FIRDatabase.database().reference(withPath: "productos").child(id)
refToProd.observeSingleEvent(of: .value, with: { snapshot in
// your value
})
}
} else {
print("productosPopulares")
}
})
不是完美的代码。应该做更多的功能。但这是想法。
希望对你有帮助
关于ios - 如何从另一个 child 查询一个 child 。火力地堡( swift ),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44399136/