【问题标题】:Firebase - Get object by userID from a list of profilesFirebase - 通过用户 ID 从配置文件列表中获取对象
【发布时间】:2016-02-24 20:20:16
【问题描述】:

我正在尝试使用 Firebase 从配置文件列表中按用户 ID 获取对象。

我正在使用 Typescript 在 Angular2 中进行编码。 我有对 firebase 工作的参考,并且可以执行其他命令,例如推送对象等。

我只需要知道如何通过字段值提取对象,例如uid 在这种情况下。

这是我的代码 sn-p:

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));     
}

*查看附件照片以查看我的 Firebase 配置文件 json。

提前致谢。

【问题讨论】:

    标签: javascript typescript firebase angular


    【解决方案1】:

    您可以使用查询。

    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('myemail@email.com');
    
    // Do a one time read of that email
    query.once('value', (snap) => console.log(snap.val()));
    

    Read the Firebase documentation for more details.

    【讨论】:

    • 当我访问 snap.val() 中的对象时,我可以看到所有字段。但是,我如何访问/附加字段,因为该对象以 firebase 键命名,例如:-K4-BInXsk3Nyw7STHxZ
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-12-12
    • 1970-01-01
    • 2020-08-13
    • 1970-01-01
    相关资源
    最近更新 更多