2012-10-01 53 views
0

我很奇怪,爲什麼_.bindAll(this, ['onSortRemove']);在下面的代碼(1)上升以下錯誤:事件綁定在Backbone.Marionette方面

Uncaught TypeError: Object [object Window] has no method 'resetItemViewContainer'

把事情的工作,我需要執行下面的代碼_.bindAll(this);

我的問題是:應該_.bindAll(this, ['onSortRemove']);夠了嗎?如果不是,爲什麼?


(1)

initialize: function() { 
     _.bindAll(this, ['onSortRemove']); // it does not work 
     _.bindAll(this); // it works 
    } 

    onSortRemove: function() { 
     setTimeout(this.render, 0); 
    } 

回答

2

語法錯誤


initialize: function() { 
    _.bindAll(this, 'onSortRemove'); // <- no array wrapper 
} 

[*methodnames]文檔的語法是不是說 「在一個陣列包裝這個」。這是老派的文檔風格,可以說「方法名是可選的,它可以是零個或多個參數,逗號分隔」。