获得骨干网/收集/ ID,而无需加载整个集合
问题描述:
有没有办法加载骨干集合的单个实体(服务器)?
Is there a way to load a single entity of a Backbone collection (from the server)?
Backbone.Collection.extend({
url: '/rest/product'
});
以下code可以用 collection.fetch加载整个集合()
但如何加载一个单一的模式? 骨干文档明确表示, GET
可以做到 /集[/ ID]
而不是如何。
The following code can load the entire collection with a collection.fetch()
but how to load a single model? Backbone's documentation says clearly that GET
can be done /collection[/id]
but not how.
答
虽然我们设置
url:"api/user"
收集,等效的模型是
for the collection, the equivalent for the model is
urlRoot:"api/user"
这会让你的时候取骨干自动补齐/ ID()
this will make backbone automatically append the /id when you fetch()