2015-11-22 26 views
2

我試圖通過使用Firebase的配置文件列表中的用戶標識獲取對象。Firebase - 通過用戶標識從配置文件列表中獲取對象

我正在用Typescript編寫Angular2。 我已經參考了firebase的工作,並可以做其他命令,如推物體等

我只需要知道如何提取一個對象的字段值,例如,在這種情況下使用。

這裏是我的代碼片段:

getUserProfileByUid(uid){ 
    console.log("Get profile by uid"); 

    var ref = new Firebase("https://markng2.firebaseio.com/profiles/uid"); 
    var data = ref.child(uid); 

    console.log(data));  
} 

*請參閱我的觀點型材火力JSON的附照片。

enter image description here

在此先感謝。

回答

3

您可以使用查詢。

var rootRef = new Firebase('<my-firebase-app>.firebaseio.com/'); 
var profileRef = rootRef.child('profiles'); 

// order by email and then find the specific email 
var query = profileRef.orderByChild('email').equalTo('[email protected]'); 

// Do a one time read of that email 
query.once('value', (snap) => console.log(snap.val())); 

Read the Firebase documentation for more details

+0

謝謝大衛 - 效果很好。 – AngularM

+0

當我訪問snap.val()中的對象時,我可以看到所有的字段。 但是,我怎麼訪問/多領域,因爲該對象的火力鍵 e.g後命名爲:-K4-BInXsk3Nyw7STHxZ – AngularM

相關問題