【问题标题】:Basic Firebase and React issue resulting in "function is undefined"导致“功能未定义”的基本 Firebase 和 React 问题
【发布时间】: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


    【解决方案1】:

    哦,伙计。这是一个简单的修复。你不能“推”到一个对象。我为一个数组切换了“posts”对象,现在它可以工作了!

    帖子 = {};

    【讨论】:

      猜你喜欢
      • 2019-07-15
      • 2018-04-23
      • 2019-05-22
      • 2017-12-04
      • 1970-01-01
      • 1970-01-01
      • 2018-10-23
      • 1970-01-01
      相关资源
      最近更新 更多