Firebase .on(“价值”)不起作用 [英] Firebase .on('value') not working
问题描述
林以下此视频此处。
以下是我的代码。
$ b index.html
<!DOCTYPE html>
< html>
< head>
< title> Fire Test< / title>
< script src =https://www.gstatic.com/firebasejs/3.2.1/firebase.js>< / script>
< / head>
< body>
<! - 值 - >
< pre id =object>< / pre>
< script src =app.js>< / script>
< / body>
< / html>
app.js
'pre>
(函数(){
//初始化火力地堡
变种配置= {
apiKey: AIzaSyCOJZqfas4gxwEYBbRNyyIy7Z9vEsTx4ME,
authDomain: fire-test-e2185.firebaseapp.com,
databaseURL: https://fire-test-e2185.firebaseio.com,
storageBucket:火试验e2185 .appspot.com的,
};
firebase.initializeApp(配置);
变种preObject =的document.getElementById( '对象');
$ b $ //创建引用
var dbRefObject = firebase.database().ref()。child('object')
console.log('test (); //记录
//同步对象变化
dbRefObject.on('value',function(snap){
console.log(snap.val() ); //不记录
));
console.log('test log'); //记录
})();
输出 然后在 我改变了这个: 至 Tough Im很确定这应该是基于firebase的标准以编程方式完成的,这只是为了测试连接的目的。 Im following this video right here. And here's my codes. index.html app.js Output BTW Here's the structure of my test project in case maybe it matters. And im running it on Actually firebase's database has it's authentication and I found out that the rules on my database is not set properly (to public). I changed this : to Tough Im pretty sure that this should be done programmatically base on firebase's standards, this is just for the purpose of testing out the connection. 这篇关于Firebase .on(“价值”)不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
fire-test
| _ index.html
| _ app.js
下使用
apache
/ var / www / html / fire-test
$ b http:// localhost / fire-test / 实际上firebase的数据库有它的身份验证,我发现我的数据库的规则没有设置正确(向公众)。
{
rules :{
.read:auth!= null,
.write:auth!= null
}
}
{
规则:{
.read:true,
.write:true
}
}
auth!= null to
true $ c $
<!DOCTYPE html>
<html>
<head>
<title>Fire Test</title>
<script src="https://www.gstatic.com/firebasejs/3.2.1/firebase.js"></script>
</head>
<body>
<!-- Value -->
<pre id="object"></pre>
<script src="app.js"></script>
</body>
</html>
(function () {
// Initialize Firebase
var config = {
apiKey: "AIzaSyCOJZqfas4gxwEYBbRNyyIy7Z9vEsTx4ME",
authDomain: "fire-test-e2185.firebaseapp.com",
databaseURL: "https://fire-test-e2185.firebaseio.com",
storageBucket: "fire-test-e2185.appspot.com",
};
firebase.initializeApp(config);
var preObject = document.getElementById('object');
// Create reference
var dbRefObject = firebase.database().ref().child('object')
console.log('test log'); // logging
// Sync object changes
dbRefObject.on('value', function (snap) {
console.log(snap.val()); // not logging
});
console.log('test log'); // logging
})();
fire-test
|_ index.html
|_ app.js
apache
under /var/www/html/fire-test
http://localhost/fire-test/
{
"rules": {
".read": "auth != null",
".write": "auth != null"
}
}
{
"rules": {
".read": true,
".write": true
}
}
"auth != null"
to true