【发布时间】:2013-07-17 14:24:08
【问题描述】:
我正在使用 Backbone 和 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 );
}
我收到此错误:
未捕获的类型错误:无法调用未定义的方法“set”
有没有办法从视图中传递引用?
【问题讨论】:
-
你看过_.bind吗?
-
@Jack
_.bind比标准Function.prototype.bind的价值是多少?向后兼容?我没有看到其他任何东西。 -
@JustinMorgan 如果标准(或者更确切地说是 native)
bind可用,则下划线将使用它。
标签: javascript backbone.js bootbox