我是第二次问这个问题,第一次把文字弄糊涂了,很抱歉。这是相同的问题得到改进和最好的解释。
我有一个PageableCollection,数据加载没有问题!表格的线条(我使用的是 backgrid,骨干网的扩展)是可编辑的!但是在编辑并按下回车键后什么也没有发生!服务器没有被调用,我等待一些调用 ajax 的服务器,但它没有发生。
我找到了覆盖同步的方法,但我真的不知道我想在编辑后拨打电话并说“好的”或“错误更新”。
代码如下:
var Territory = Backbone.Model.extend({});
var PageableTerritories = Backbone.PageableCollection.extend({
model: Territory,
url: "linhas/results",
state: {
pageSize: 9
},
mode: "client",
sync: function (method, model, options){
return Backbone.sync(method, model, options);
}
});
var pageableTerritories = new PageableTerritories(),
initialTerritories = pageableTerritories;
function createBackgrid(collection){
var columns = [{
name: "id", // The key of the model attribute
label: "ID", // The name to display in the header
editable: false, // By default every cell in a column is editable, but *ID* shouldn't be
// Defines a cell type, and ID is displayed as an integer without the ',' separating 1000s.
cell: Backgrid.IntegerCell.extend({
orderSeparator: ''
})
}, {
name: "name",
label: "Name",
// The cell type can be a reference of a Backgrid.Cell subclass, any Backgrid.Cell subclass instances like *id* above, or a string
cell: "string" // This is converted to "StringCell" and a corresponding class in the Backgrid package namespace is looked up
}, {
name: "pop",
label: "Population",
cell: "integer" // An integer cell is a number cell that displays humanized integers
}, {
name: "url",
label: "URL",
cell: "uri" // Renders the value in an HTML <a> element
}];
if ($(window).width() < 768){
//okendoken. removing URL-column for screens smaller than 768px
columns.splice(3,1)
}
var pageableGrid = new Backgrid.Grid({
columns: columns,
collection: collection,
footer: Backgrid.Extension.Paginator.extend({
//okendoken. rewrite template to add pagination class to container
template: _.template('<tr><td colspan="<%= colspan %>"><ul class="pagination"><% _.each(handles, function (handle) { %><li <% if (handle.className) { %>class="<%= handle.className %>"<% } %>><a href="#" <% if (handle.title) {%> title="<%= handle.title %>"<% } %>><%= handle.label %></a></li><% }); %></ul></td></tr>')
}),
className: 'table table-striped table-editable no-margin'
});
$("#table-dynamic").html(pageableGrid.render().$el);
}