【发布时间】:2011-05-31 14:57:29
【问题描述】:
创建集合时,Backbone 一次性配置 url。以后有办法改这个网址吗?
以下示例显示在 /product 的 2 个 POST 和在 /product/id/stock 的 2 个 POST。最后一个POST 不行,Backbone 连接 id 并尝试PUT 它,但我不知道为什么。
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 });
}
股票收藏:
Backbone.Collection.extend({
url: function() {
return this.url;
},
parse : function(resp) {
return resp.stock;
},
setProduct: function(id) {
this.url = '/product/'+id+'/stock';
}
});
这行不通。
【问题讨论】:
标签: url collections backbone.js