Firebase:数据库引用“打开"方法未运行回调(javascript) [英] Firebase: Database reference 'on' method not running callback (javascript)

查看:41
本文介绍了Firebase:数据库引用“打开"方法未运行回调(javascript)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在查询可能不存在的数据.在这种情况下,将不运行回调.据我了解,它应该运行,并且snapshot.val()应该为null,不是吗?

I'm tunning a query for data that may not exist . When this is the case, the callback is not run. As I understand from the docs, it should run and the snapshot.val() should be null, isn't it?

这里有一个简化的示例: http://surfmaps.eu/trombone/case.html

There's a stripped down example here: http://surfmaps.eu/trombone/case.html

在回调中有一个console.log未被执行.

There's a console.log inside the callback that is not executed.

我在这里想念东西吗?

再见,谢谢路易斯

代码:

function getData(id) {
    var ref=firebase.database().ref("support/"+id); 
    console.log("In getData, looking for ",ref);

    // get support data from firebase
    ref.on('value',function (snapshot) {
        console.log("In Value");
        console.log(snapshot);
    });

    console.log("end getData, looking for ",ref);

}

// on startup
getData("abc");

推荐答案

您无权读取数据.要看到这一点,您可以附加一个完成侦听器并记录它给您的错误:

You don't have permission to read the data. To see this, you can attach a completion listener and log the error it gives you:

var ref=firebase.database().ref("support/"+id); 
console.log("In getData, looking for ",ref);

// get support data from firebase
ref.on('value',function (snapshot) {
    console.log("In Value");
    console.log(snapshot);
}, function(error) {
    console.error(error);
});

console.log("end getData, looking for ",ref);

这样做表明:

错误:/support/abc中的权限被拒绝:客户端没有访问所需数据的权限.

Error: permission_denied at /support/abc: Client doesn't have permission to access the desired data.

这篇关于Firebase:数据库引用“打开"方法未运行回调(javascript)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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