【发布时间】:2018-12-03 06:44:40
【问题描述】:
我目前有这个功能:
<script>
function firebase_database(){
var docRef = firebase.collection("signs").doc("PuA9s68iuxBnJo7PEezC");
docRef.get().then(function(doc) {
if (doc.exists) {
console.log("Document data:", doc.data());
} else {
// doc.data() will be undefined in this case
console.log("No such document!");
}
}).catch(function(error) {
console.log("Error getting document:", error);
});
}
</script>
我尝试用
调用它<script> firebase_database() </script>
但我明白了
(index):823 Uncaught TypeError: firebase.collection is not a function
at firebase_database ((index):823)
at (index):836
SN:第一次接触 JS
【问题讨论】:
-
firebase_database() -
该函数需要以某种方式被调用或触发。如果您希望它在加载特定元素时运行,您可以使用
onReady事件回调,绑定到特定的 HTML 元素。这只是一个例子,请澄清您的问题。 -
问题似乎与您在 head 部分中加载相关文件的方式或其他方式有关。您必须先加载依赖项才能使用它们。
-
我希望它在网站加载后立即运行。我试过 firebase_database();但我不断收到
(index):823 Uncaught TypeError: firebase.collection is not a function at firebase_database ((index):823) at window.onload ((index):839) -
你的函数调用了另一个不存在的函数——至少不在当前范围内。
标签: javascript