2013-04-22 199 views
0

我正在使用backbone和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現在與調試問題日誌但它永遠不會發生,任何想法爲什麼?

回答

0

所以事實證明,我使用的骨幹版本不是允許通過on函數進行多個事件綁定的版本。

已更新至1.0.0,現在開始工作。