ios - 如何从另一个 child 查询一个 child 。火力地堡( swift )

标签 ios swift firebase firebase-realtime-database

我正在开发一个交付应用程序。所以我在 firebase 中有 productos 和流行的产品:

  • 产品

Products

  • PopularProducts(产品 ID 作为键,true 作为值)

PopularProducts

如何只查询使用这些 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/

相关文章:

ios - 将 UIPageControl 添加到 UIScrollView

ios - UIFont 等宽数字+小型大写字母

javascript - 如何查询 Firebase 的 equalTo bool 参数?

iphone - UITableviewCell 意外更改

iphone - 旧版本的 iOS 用户可以浏览最新 iOS 独占的应用程序吗? (例如 iOS5 用户在 App Store 中看到 iOS6 应用程序)

ios - ios 中的自动完成文本字段

ios - 为什么 calloutAccessoryControlTapped 也会在注释 View 上被调用?

ios - 具有 2 路绑定(bind)的 KVO 无限循环

firebase - 如何在 Firestore 中存储 Markdown 文本?

java - 如何在Cloud Firestore中仅在第一笔交易成功后才进行另一笔交易?