【问题标题】:getting started with firebase with javascript使用 javascript 开始使用 firebase
【发布时间】:2017-09-23 21:54:18
【问题描述】:

我刚刚开始使用 firebase 和 javascript html 为我的应用创建网站。

我要做的就是从 firebase 访问任何值并将其打印在网站上。

我按照 firebase 的快速入门教程复制了与他们完全相同的代码:https://www.youtube.com/watch?v=k1D0_wFlXgo

代码如下:

<!DOCTYPE html>

<html>
    <head>
    <meta charset="utf-8">
    <title>Javascript</title>

    </head>


<body>

    <h1 id="bigOne"></h1>
    <script src="https://www.gstatic.com/firebasejs/3.3.2/firebase.js"></script>
    <script>
  // Initialize Firebase
        var config = {
        apiKey: "AIzaSyD0C9hhfpdKEIahisG0VNInZZGjCyf5Lo0",
        authDomain: "game-of-chats-ce897.firebaseapp.com",
        databaseURL: "https://game-of-chats-ce897.firebaseio.com",
        storageBucket: "game-of-chats-ce897.appspot.com",
        };
        firebase.initializeApp(config);
        var bigOne = document.getElementById('bigOne');
        var dbRef = firebase.database().ref().child('text');

        dbRef.on('value', snap => bigOne.innerText) = snap.val())

    </script>
</body>

</html>

我错过了什么吗?我是新人,所以我可能缺少一小步。

【问题讨论】:

  • 这行末尾有一个额外的) dbRef.on('value', snap =&gt; bigOne.innerText) = snap.val())
  • 但作为旁注,我还建议您检查console.firebase.google.comDatabases 下的规则,以确保您确实拥有read/write 权限!对于开发,您可以将false 更改为true

标签: javascript html firebase firebase-realtime-database


【解决方案1】:

试试:

dbRef.on('value', function(snapshot) {
    bigOne.innerText = snapshot.val();
});

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-01-15
    • 2016-11-08
    相关资源
    最近更新 更多