我使用主干事件将上下文(视图对象)绑定到事件处理程序,这有点工作,但问题是在触发事件时,在初始化方法中设置的任何属性似乎都没有跟随上下文。下面的代码说明了这个问题:
define(['backbone'], function( Backbone ) {
var PageView = Backbone.View.extend({
/* Globals */
pageExist: false,
initialize: function( options ) {
var self = this;
self.pageExist = true;
// _mediator is passed during instantition of the view
// I've removed the code here as it's not relevant for this problem
self._mediator.on("pin:add", self._pinAddCB, self);
// Using bindAll seems a little bit better as the context now carries the aditional method that i added on this view ( like _pinAddCB )
_.bindAll();
},
_pinAddCB: function( ) {
console.log(this.pageExist ) // FALSE ??
}
});
return PageView;
});
关于如何解决这个问题的任何想法?