【发布时间】:2015-11-28 05:20:00
【问题描述】:
使用:React.js、Firebase 和 Browserify
我正在做一个简单的教程,我 95% 的错误只是一些菜鸟错误。我一直在搜索和调整一段时间,但我被卡住了
错误:此警告 FIREBASE 警告:用户回调引发异常。 TypeError: undefined is not a function导致这个错误Uncaught TypeError: undefined is not a function
洞察:根据编译器,当事件监听器为“child_added 方法”调用我的辅助方法“addPosts”时,它是未定义的。
代码:
var ChatServerActionCreators = require('../actions/ChatServerActionCreators');
var firebaseUrl = "https://changedthispurposely.firebaseio.com";
//Up here I will place my firebase event handler
var postBoxRef = new Firebase(firebaseUrl + "/post");
var posts = {};
function addPosts(author,text){
posts.push({"author":author,"text":text});
}
postBoxRef.on("child_added", function(snapshot) {
var newPost = snapshot.val();
addPosts(newPost.author, newPost.text);
});
module.exports = {
getAllPosts: function() {
var rawPosts = posts;
console.log(rawPosts);
}
};
【问题讨论】:
标签: reactjs firebase undefined browserify