Мой тривиальный дизайн CRUD REST выглядит следующим образом:Backgrid REST дизайн: ID не передается автоматически в URL
create: [USERID]/weights/
read: [USERID]/weights/[ITEMID]
update: [USERID]/weights/[ITEMID]
delete: [USERID]/weights/[ITEMID]
Я попытался backgrid и methodToURL. Все, что я достиг:
create: [USERID]/weights/
read: [USERID]/weights/
update: [USERID]/weights/
delete: [USERID]/weights/
т. Е. ПУНКТ не передается вообще. Даже без методаToURL backgrid не пропускает ITEMID. Теперь я потерян. Какие-либо предложения?
Вот мой имп. покупок:
var Weight = Backbone.Model.extend({
urlRoot: "weights",
initialize: function() {
Backbone.Model.prototype.initialize.apply(this, arguments);
this.on("change", function(model, options) {
console.log("Saving change");
if (options && options.save === false)
return;
model.save();
});
},
methodToURL: {
'read': '/' + sesUserId +'/weights/',
'create': '/' + sesUserId +'/weights/',
'update': '/' + sesUserId +'/weights/',
'delete': '/' + sesUserId +'/weights/'
},
sync: function(method, model, options) {
options = options || {};
options.url = model.methodToURL[method.toLowerCase()];
Backbone.sync(method, model, options);
}
});
var PageableWeightTable = Backbone.PageableCollection.extend({
model: Weight,
url: '/' + sesUserId +'/weights/',
state: {
pageSize: 10
},
mode: "client" // page entirely on the client side
});
var weightTable = new PageableWeightTable();
var grid = new Backgrid.Grid({
columns: [{
// name is a required parameter, but you don't really want one on a select all column
name: "",
// Backgrid.Extension.SelectRowCell lets you select individual rows
cell: "select-row",
// Backgrid.Extension.SelectAllHeaderCell lets you select all the row on a page
headerCell: "select-all"
}].concat(columns),
collection: weightTable
});
var $divWeightTable = $("#divweighttable");
$divWeightTable.append(grid.render().$el);
var paginator = new Backgrid.Extension.Paginator({
collection: weightTable
});
$divWeightTable.append(paginator.render().$el);
weightTable.fetch({ reset: true });