[英]Uncaught Error : Action is missing a listen method React/Reflux?
I am New to React Redux.This is a simple App I am developing.But Error is I can't connect to store through Action. 我是React Redux的新手。这是我正在开发的一个简单的应用程序。但错误是我无法通过Action连接到商店。
This is my error 这是我的错误
utils.js:78 Uncaught Error: action is missing a listen method
utils.js:78未捕获错误:操作缺少listen方法
topic-list.js 话题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 actions.js
var Reflux = require('reflux');
module.exports = Reflux.createAction([
'getTopics',
]);
topic-store.js 话题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)
}
});
The error message implies you are trying to listen to something which can't be listened to (ie. it doesn't have a listen method.) 错误消息暗示您正在尝试收听无法收听的内容(即,它没有监听方法。)
That means the source of the error can either be: 这意味着错误的来源可以是:
listenables:[Actions]
from topic-store.js
listenables:[Actions]
来自topic-store.js
listenables:[Actions]
Reflux.listenTo(TopicStore,'onChange')
from topic-list.js
topic-list.js
Reflux.listenTo(TopicStore,'onChange')
I believe it's the former, as there is a typo in actions.js
, as the method is Reflux.createActions
, not Reflux.createAction
. 我相信它是前者,因为
actions.js
存在拼写错误,因为方法是Reflux.createActions
,而不是Reflux.createAction
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.