在使用此mixin构建的网站上切换按钮时,它会创建错误,即:bool
我添加了View和store文件,帖子如下。当我按下按钮时发生错误:"注册" &安培; "登录"
但是在页面重新加载之后,它工作正常。我的SoreMixin文件如下:
Uncaught TypeError: store.off is not a function
存储文件:
/** @jsx React.DOM *//**
* mixin to let components listen to stores in a simple way
* the component needs to implement `onStoreUpdate` to set the state
* @param {Object} store
* @param {String} [events="add remove reset change"]
*/
module.exports = function(store, events) {
if(!events) {
events = "add remove reset change";
}
return {
componentDidMount: function() {
store.on(events, function() {
this.forceUpdate();
}, this);
},
componentWillUnmount: function() {
store.off(null, null, this);
}
};
};
查看文件:
var Backbone = require('backbone');
var Dispatcher = require('project/shared/dispatcher');
var baseStore = {
/**
* backbone init method
*/
initialize: function() {
this.dispatchId = Dispatcher.register(this.handleDispatch.bind(this));
},
/**
* handle the dispatcher actions
* @param {Object} payload
*/
handleDispatch: function(payload) { }
};
module.exports =
{
BaseStore : baseStore,
Model: Backbone.Model.extend(baseStore),
Collection: Backbone.Collection.extend(baseStore)
};
答案 0 :(得分:0)
你商店里没有.off()函数,这就是原因。
使用eventEmiter https://facebook.github.io/flux/docs/todo-list.html#creating-stores
阅读此示例您将使用.on和removeListener(而不是.off())