Firebase - 从嵌套结构中提取对象的数据结构问题 [英] Firebase - Data structure issue for extracting an object from nested structure

查看:127
本文介绍了Firebase - 从嵌套结构中提取对象的数据结构问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Firebase - 从嵌套结构中提取对象的数据结构问题。

我想查找uid,然后检查键是否是jobId。
我在下面标记了相应的内容。

我使用的是带有firebase的typescript和angular2。



这是我目前的尝试返回null:

  var jobId =-K5fIAiuHM- 4xeEQJiIS; 
var uid =3f61ae7a-99a1-4cbf-9c8e-00b2249956a7;

var userRef = this.refApp.child('key')。child(uid);
var query = userRef.child('jobId')。child(jobId);
$ b query.on('value',(snap)=> {

//返回null
var response = snap.val();
});

这是我的数据库结构:

$ C> /应用/ $用户ID / $的jobId 。使用这些密钥来获取您的数据。



JSBin Demo

  var jobId =-K5fIAiuHM-4xeEQJiIS; 
var uid =3f61ae7a-99a1-4cbf-9c8e-00b2249956a7;
var refApp = new Firebase('< my-firebase-app> / applications');
var jobRef = refApp.child(uid).child(jobId);
jobRef.on('value',(snap)=> console.log(snap.val()));

现在您正在使用key,我相信是从我以前的演示。这只是为了展示,而不是为了您的实际解决方案。阅读示例代码时请牢记数据结构,因为它可能会有所不同。


Firebase - Data structure issue for extracting an object from nested structure.

I want to find the uid and then check if the key is a jobId. I've labelled accordingly below.

I'm using typescript and angular2 with firebase.

This is my current attempt that returns "null":

        var jobId = "-K5fIAiuHM-4xeEQJiIS";
        var uid = "3f61ae7a-99a1-4cbf-9c8e-00b2249956a7";

        var userRef = this.refApp.child('key').child(uid);
        var query = userRef.child('jobId').child(jobId);

        query.on('value', (snap) => {

            //This returns null
            var response = snap.val();
        });

This is my database structure:

解决方案

Your structure is /applications/$userId/$jobId. Use those keys to get to your data.

JSBin Demo

var jobId = "-K5fIAiuHM-4xeEQJiIS";
var uid = "3f61ae7a-99a1-4cbf-9c8e-00b2249956a7";
var refApp = new Firebase('<my-firebase-app>/applications');
var jobRef = refApp.child(uid).child(jobId);
jobRef.on('value', (snap) => console.log(snap.val()));

Right now you're using "key", which I believe is from my previous demo. That's just for show, not for your actual solution. Keep your data structure in mind when reading the sample code, because it can vary.

这篇关于Firebase - 从嵌套结构中提取对象的数据结构问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆