【问题标题】:How to use wildcards in a firebase observer path ?如何在 firebase 观察者路径中使用通配符?
【发布时间】:2018-10-17 19:55:30
【问题描述】:

是否可以在 firebase 观察者的路径中使用通配符?

现在我有:

self.ref?.child('root').child('info').observe(
    DataEventType.childChanged, with: { (snapshot) -> Void in

    //do something   

})

有没有什么办法可以实现:

self.ref?.child('root').child('info').child(<wildcard>).child('details').observe(
     DataEventType.childChanged, with: { (snapshot) -> Void in

    //find out what the wildcard is & do something

})

谢谢

【问题讨论】:

    标签: swift firebase firebase-realtime-database swift4 observers


    【解决方案1】:

    没有办法像这样观察节点的子集。您的选择是:

    1. 观察info的所有子节点,其中childAdded等。
    2. details 移动到新的顶级节点并在那里观察。

    第一个选项适用于您当前的数据结构。但它会读取比您感兴趣的更多数据。第二个选项不会下载太多数据,但您需要更改数据结构。

    【讨论】:

      猜你喜欢
      • 2018-11-29
      • 2017-01-26
      • 2020-01-02
      • 1970-01-01
      • 2017-05-23
      • 2018-09-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多