Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/backbone.js/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Backbone.js 主干模型事件未触发_Backbone.js_Requirejs_Backbone Events - Fatal编程技术网

Backbone.js 主干模型事件未触发

Backbone.js 主干模型事件未触发,backbone.js,requirejs,backbone-events,Backbone.js,Requirejs,Backbone Events,我在requirejs中使用主干,我在全局应用程序对象上触发一个事件,并在应用程序启动句柄时进行设置,但由于某些原因,事件没有被捕获。以下是应用程序中的代码: main.js require([ "app", "router", "modules/facebookLogin" ], function(app, Router,FacebookLogin) { // Define your master ro

我在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:已连接”

而响应是正确的对象


现在我用日志替换了app.Router.nagigate来调试这个问题,但从来没有发生过,你知道为什么吗?

所以我使用的主干网版本不是允许通过on函数进行多事件绑定的版本

更新到1.0.0,现在可以使用了