-2
我有一个骨干网格/可编辑网格,每次编辑一个单元格时,“更改”事件被激发两次,最终生成两个单独的PUT请求。骨干网格:如何避免双重变更事件
我知道发生这种情况是因为“change”事件在单元格中编辑时触发一次,而另一个数据从服务器返回时触发;并且可以通过将{wait: true}
传递给save
方法来避免该行为,但我不知道在哪里需要重载它。
我的模型的声明是这样的:
var Redirects = Backbone.Model.extend({
urlRoot: '/global/redirects',
initialize: function() {
Backbone.Model.prototype.initialize.apply(this, arguments);
this.on("change", function (model, options) {
if (options && options.save === false) return;
model.save({
error: alertMe
});
});
this.on('fetch request', function (e) {
loadingOn(e);
});
this.on('sync error', function (e) {
loadingOff(e);
});
this.on('error', function(e, resp){
alertMe(e, resp);
});
}
});