【问题标题】:RubyMotion Firebase (motion-firebase) How to retrieve data?RubyMotion Firebase (motion-firebase) 如何检索数据?
【发布时间】:2015-11-03 04:05:32
【问题描述】:

使用 RubyMotion Firebase (https://github.com/colinta/motion-firebase) 的 motion-firebase 库,我可以通过以下方式轻松设置数据:

firebase.set({ full_name: ['first_name' => 'Fred', 'last_name' => 'Flintstone'] })

firebase['first_name'] = 'Fred'

但我无法弄清楚如何检索数据。

我已经尝试了响应自述文件中列出的不同 firebase.query 方法,但我肯定遗漏了一些东西。

我希望它会像这样简单:

firebase.query['first_name']
=> 'Fred'

谁能解释一下我如何使用key 查询Firebase 并返回value

【问题讨论】:

    标签: firebase rubymotion


    【解决方案1】:

    科林塔在这里!您需要附加一个观察者 (https://github.com/colinta/motion-firebase#attaching-observers-to-read-data)。

    firebase_ref.once(:value) { |snapshot| snapshot.value }

    有关FDataSnapshot 类型的信息,请参阅https://www.firebase.com/docs/ios-api/Classes/FDataSnapshot.html

    【讨论】:

    • 你知道是否有办法获取单个键的值。或者换句话说,使用单个键查询 Firebase?
    • 是的,firebase_ref 不必是根 ref,它可以是任何 url。例如username_ref = root_ref['user'][id]['username']。然后,如果您正在侦听“更改”事件,您只会听到对 /user/[id]/username 的更改。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-11-19
    • 2016-11-22
    • 1970-01-01
    • 1970-01-01
    • 2016-12-29
    • 1970-01-01
    相关资源
    最近更新 更多