我使用Backbone和bootbox。 这是我的代码视图中:通过Backbone将“this”传递给Bootbox回调
confirm : function(result) {
if (result === true) {
var that = this;
this.model.set({completed: '1'}); // Exception here
this.model.save(
null, {
success: function (model, response) {
Backbone.history.navigate("index", true);
},
error: function(model, response) {
that.model.set({completed: '0'});
var responseObj = $.parseJSON(response.responseText);
bootbox.alert(responseObj.message);
}
});
}
},
completeProcess : function(event) {
event.preventDefault();
this.model.set({completed: '1'});
bootbox.confirm("Confirm?", this.confirm);
}
我得到这个错误:
Uncaught TypeError: Cannot call method 'set' of undefined
有没有办法通过视图中的参考?
你看过[_.bind](http://underscorejs.org/#bind)吗? – Jack
@Jack标准'Function.prototype.bind'上'_.bind'的值是多少?向后兼容?我什么都看不到。 –
@JustinMorgan如果标准(或者说一个* native *)'bind'可用,则下划线将使用它。 – Jack