Firebase 3 - 无法从数据库检索数据(Web) [英] Firebase 3 - Can't retrieve data from database (Web)
问题描述
我第一次使用 Firebase 3
(最新版本)开发web应用程序,但遇到了检索数据的麻烦
我从<$创建了一个 NodeJS
测试应用程序c $ c> Heroku ,然后我试图以JSON格式(ref的路径到我的数据数组)保存在我的Firebase 实时数据库
。
我遵循文档,但没有结果。
以下是我的代码:
< script src =https://www.gstatic.com/firebasejs/live/3.0/firebase.js>< / script>
< script>
//初始化Firebase
var config = {
apiKey:*******,
authDomain:******* ,
databaseURL:*******,
storageBucket:*******,
};
firebase.initializeApp(config); $()
firebase.database()。ref('my / path / to / data')。登录控制台
});
< / script>
控制台中没有错误,但没有结果。这似乎是如此简单,但我无法弄清楚我缺少的东西。
这一直在我的工作应用程序:
$ $ $ $ $ c $ firebase.database $ b $ .ref(`/ database / path`)
。一次('value')
。然后((snapshot)=> {console.log('hi')});
I'm working on a webapp using Firebase 3
(the latest version) for the first time but I'm having troubles with retrieving data
on my page.
I've created a NodeJS
test app from Heroku
, then I'm trying to retrieve my data in JSON format (ref's path goes to my data array) saved in my Firebase realtime database
.
I've followed the doc, but without results.
Here's my code:
<script src="https://www.gstatic.com/firebasejs/live/3.0/firebase.js"></script>
<script>
// Initialize Firebase
var config = {
apiKey: "*******",
authDomain: "*******",
databaseURL: "*******",
storageBucket: "*******",
};
firebase.initializeApp(config);
firebase.database().ref('my/path/to/data').on('value', function(snapshot) {
console.log('kk'); //no log in the console
});
</script>
There are no errors in the console, but no results too. It seems so simple to do but I can't figure out what I'm missing.
This has been working in my application:
firebase.database()
.ref(`/database/path`)
.once('value')
.then((snapshot) => { console.log('hi') });
这篇关于Firebase 3 - 无法从数据库检索数据(Web)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!