在Backbone.js的视图中我有初始化和fillTerminal函数,如
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(
)但没有成功。这是什么解决方案?
答案 0 :(得分: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);
}