我正在使用带有 requirejs 的主干,我在全局应用程序对象上触发了一个事件,并在应用程序启动句柄时进行了设置,但由于某种原因,该事件没有被捕获。这是应用程序的代码:
main.js
require([
"app",
"router",
"modules/facebookLogin"
],
function(app, Router,FacebookLogin) {
// Define your master router on the application namespace and trigger all
// navigation from this instance.
app.router = new Router();
app.currentFacebookSession = new FacebookLogin.Model();
app.currentFacebookSession.on({
'facebook:unauthorized': function () {
//app.router.navigate('', true);
},
'facebook:disconnected': function () {
//app.router.navigate('', true);
},
'facebook:connected': function () {
//app.router.navigate('events', true);
console.log('EVENTS');
}
});
// Trigger the initial route and enable HTML5 History API support, set the
// root folder to '/' by default. Change in app.js.
Backbone.history.start({ pushState: true, root: app.root });
//Init facebook
...
模型是 facebookLogin.js
// Facebookuser module
define(["app", "facebookSDK"],
// Map dependencies from above array.
function(app,FB) {
// Create a new module.
var FacebookLogin = app.module();
// Default Model.
FacebookLogin.Model = Backbone.Model.extend({
initialize: function (attributes, options) {
options || (options = {});
this.options = _.defaults(options, this.defaultOptions);
this.facebookInitialize();
_.bindAll(this, 'onLoginStatusChange');
FB.Event.subscribe('auth.authResponseChange', this.onLoginStatusChange);
},
.....
onLoginStatusChange: function (response) {
if (this._loginStatus === response.status) return false;
var event;
if (response.status === 'not_authorized') {
event = 'facebook:unauthorized';
} else if (response.status === 'connected') {
event = 'facebook:connected';
if (this.options.autoFetch === true) this.fetch();
} else {
event = 'facebook:disconnected';
}
this.trigger(event, this, response);
this._loginStatus = response.status;
},
在调试时,它涉及到触发器并使用以下参数运行触发器。
this.trigger(event, this, response);
这=
child
_changes: Object
_escapedAttributes: Object
_pending: Object
_previousAttributes: Object
attributes: Object
changed: Object
cid: "c0"
id: ""
onLoginStatusChange: function bound() {
options: Object
__proto__: Surrogate
事件 ="facebook:connected"
并且响应是正确的对象
我现在替换了 app.Router.nagigate 以用日志调试问题,但它从未发生过,有什么想法吗?