2012-05-16 41 views
0

Backbone.js的內部的觀點我已經初始化和fillTerminal功能,如調用外部函數裏面Backbone.js的的觀點初始化方法

fillTerminal: function() { 
    // something to print 
}, 
initialize: function() { 
    this.model.bind('change:attr', function(styleProperty, styleValue) { 
     // here I want to call fillTerminal function 
    }); 
} 

我試着像fillTerminal()this.fillTerminal(),但沒有成功。這是什麼解決方案?

回答

3

當你在這種情況下綁定時,你必須傳遞「this」的上下文。你可以在這裏閱讀更多關於上下文參數:http://documentcloud.github.com/backbone/#Events

fillTerminal:function(){ 
    //something to print 
}, 

initialize : function() { 
    this.model.bind('change:attr', function(styleProperty, styleValue) { 

     // here I want to call fillTerminal function 
     this.fillTerminal(); 

    }, this); 
}