EmberJS:如何在ember-data RESTAdapter中为模型提供特定的URL? [英] EmberJS: How to provide a specific URL for a model in ember-data RESTAdapter?
问题描述
问题1:
如果我有一个名为公司的余烬数据模型,如何告诉它点击 / business
和 /business /:id
来检索记录?有没有办法为给定模型指定网址?更好的是,像BackboneJS,我可以在运行时计算模型的URL吗?
Question 1:
If I have a ember-data model called "Company", how do I tell it to hit /businesses
and /businesses/:id
to retrieve records instead? Is there a way to specify the url for a given model? Even better, like BackboneJS, can I compute a URL for the model at runtime?
问题2:
我有一个独特的要求,我的API是有组织的这样:
Questions 2: I have somewhat a unique requirement, my API is organized this way:
/ api / v1 / company /:company_id / form /:form_id / items /:item_id
有没有办法用EmberJS来处理这个问题?我理解ember有DS.hasMany('App.Items')这种关系,但它们似乎点击 / items /:item_id
URL来获取数据而不是完整的网址。
Is there a way to handle this with EmberJS? I understand ember has the DS.hasMany('App.Items') kind of relationships, but they seem to hit the /items/:item_id
URL to get the data instead of the full URL.
如何处理此问题?
推荐答案
<回答你的第一个问题,当你在创建商店时,你可以这样做:
Answering to your first question, when you're creating your store, you can do this:
DS.RESTAdapter.configure("plurals", {
company: "businesses"
});
至于你的第二个问题,基于这些指南我相信你可以像下面这样命名空间,用你的公司替换id和表单信息,但是我之前没有这样做过,所以我无法确定这是否有效。假设你在知道这些ID的应用程序中登陆,你可以从技术上取代它们:
As for your second question, based on these guides I believe you can a namespace like the following, replacing the ids with your company and form information, but I haven't done this before so I can't tell for sure this would work. Assuming you land in your application knowing these ids, you could technically replace them:
DS.RESTAdapter.reopen({
namespace: '/api/v1/company/<replace>/form/<replace>'
})
你也可以尝试设置模型 url
。
You could also try setting the model url
.
你可以阅读更多关于这个这里
You can read more about this here
这篇关于EmberJS:如何在ember-data RESTAdapter中为模型提供特定的URL?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!