我有一个视图,其中包含员工列表,最终用户选择员工,并删除员工在一个以上。
列表的每一行都包含一个复选框。最终用户选中多个复选框,然后按delete按钮。选中的记录需要删除。
MVC控制器负责删除部分。delete方法的签名为:
DeleteEmployes(List<int> empIds).我如何才能做到这一点?
我的主干模型是:
var emp = Backbone.Model.extend({
defaults:{
Id:null,
fname:null,
lname:nulll.
}
});发布于 2013-12-09 09:01:44
为了通过一个请求删除所有模型,您需要使用一个方法来扩展backbone的集合,该方法将HTTP delete请求发送到使用'DeleteEmployes(List empIds)‘函数的控制器操作。像这样的东西可能会起作用。
Backbone.Collection.prototype.bulk_destroy = function() {
var modelId = function(model) { return model.id };
var ids = this.models.map(modelId);
// Send ajax request (jQuery, xhr, etc) with the ids attached
// Empty the collection after the request
// You may want to include this as a success callback to the ajax request
this.reset();
};发布于 2013-12-08 06:24:30
创建一个Backbone Collection并对其进行循环,销毁每个模型。这会将每个模型的删除命令发送到服务器。
var Employees = new Backbone.Collection([
{ name: 'Employee1' },
{ name: 'Employee2' },
{ name: 'Employee3' },
]);
Employees.each(function(model){
model.destroy();
});https://stackoverflow.com/questions/20445628
复制相似问题