获得骨干网/收集/ ID,而无需加载整个集合 [英] Get /collection/id in backbone without loading the entire collection

查看:127
本文介绍了获得骨干网/收集/ 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()

这篇关于获得骨干网/收集/ ID,而无需加载整个集合的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆