2015-11-03 153 views
1

使用了RubyMotion火力地堡運動火力庫(https://github.com/colinta/motion-firebase)我可以設置數據很容易,無論是這樣做的:RubyMotion 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查詢火力地堡並返回value

回答

2

colinta here!您需要附上觀察員(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

+0

您是否知道是否有辦法獲得單個密鑰的價值。換句話說,用單個鍵查詢Firebase? – YoDK

+0

是的,'firebase_ref'不一定是root ref,它可以是任何url。例如'username_ref = root_ref ['user'] [id] ['username']'。然後,如果您正在偵聽「更改」事件,則只會聽到有關'/ user/[id]/username'的更改。 – colinta