未捕获错误:操作缺少侦听方法React / Reflux?

时间:2016-08-25 13:51:44

标签: javascript reactjs refluxjs

我是React Redux的新手。这是我正在开发的一个简单的应用程序。但错误是我无法通过Action连接到商店。

这是我的错误

  

utils.js:78未捕获错误:操作缺少监听方法

主题的list.js

    var React = require('react');
var Reflux = require('reflux');
var TopicStore = require('../stores/topic-store');
var Actions = require('../actions');

module.exports = React.createClass({
    mixins:[
      Reflux.listenTo(TopicStore,'onChange')  
    ],
    getInitialState:function () {
      return{
          topics:[]
      }
    },
    componentWillMount:function () {
       //Actions.getTopics()
        Actions.getTopics()
    },
    render:function () {
      return <div className="list-group">
          ToPic List
          {this.renderTopics()}
      </div>
    },
    renderTopics:function () {

        return this.state.topics.map(function(topic) {
            return <li key={topic.id}>
                {topic.description}
            </li>

        })

    },
    onChange:function (evet,topics) {
        this.setState({topics:topics})
    }


});

actions.js

var Reflux = require('reflux');

module.exports = Reflux.createAction([
    'getTopics',

]);

主题的store.js

    var Api = require('../utils/api');
var Reflux = require('reflux');
var Actions = require('../actions');


module.exports = Reflux.createStore({
    listenables:[Actions],
   getTopics:function () {
       return Api.get('topics/defaults')
           .then(function (json) {
               this.topics = json.data;
               this.triggerChange();
           }.bind(this));
   },
    con:function () {
      console.log('Working')
    },
    triggerChange:function () {
        this.trigger('change',this.topics)

    }
});

1 个答案:

答案 0 :(得分:0)

错误消息暗示您正在尝试收听无法收听的内容(即,它没有听取方法。)

这意味着错误的来源可以是:

    来自listenables:[Actions]
  1. topic-store.js 来自Reflux.listenTo(TopicStore,'onChange')
  2. topic-list.js

    我认为它是前者,因为actions.js中存在拼写错误,因为方法是Reflux.createActions,而不是Reflux.createAction