Backbone configure the url once for everyone when creating the collection. Is there a way to change this URL later?
The following example shows 2 POSTs under /product
and 2 POST
under /product/id/stock
. The last POST
will not work, Backbone combines the id and tries to PUT
it, but I do not know why.
products.create({ name: 'American Pastoral', price: 8 }); products.create({ name: 'The Grapes of Wrath', price: 10 }); products.each(function(product) { var id = parseInt(product.get('id')); stocks.setId(id); stocks.create({ id: id, quantity: 12 }); }
Stock Collection:
Backbone.Collection.extend({ url: function() { return this.url; }, parse : function(resp) { return resp.stock; }, setProduct: function(id) { this.url = '/product/'+id+'/stock'; } });
This one will not work.
yves amsellem
source share