我有类似的代码
(function(exports, $, Backbone, document){
"use strict";
var modals = {
"Alerts.alert_delete" : (function() {
var self = this;
return {
template : {
count : this.collection.length,
models : this.collection.models
},
events : {
"click .confirm" : function(event) {
event.preventDefault();
var modal = this,
finished = _.after(modal.collection.length, self.reDraw);
// Models are succesfully delete, but finished is not completed
this.collection.each(function(model) {
modal.collection.sync('delete', model, { success : finished });
});
}
}
};
})
};
exports.app.modal = function(name, context) {
return modals[name].call(context);
};
}(this, jQuery, Backbone, document));
请忽略抽象,这是为了允许我对所有模态使用一个通用视图,同时保持独特的逻辑抽象。我不知道为什么_.after
函数在被正确调用次数后没有完成。self
在这种情况下是对父视图的引用。
有人可以为我解释一下吗?