Rest 余烬模型重新适应嵌套端点
我正在使用Ember 1.5构建一个web应用程序,并使用Ember Model 0.0.11将该应用程序链接到API。我目前在让Ember模型使用嵌套API端点方面遇到了问题 例如,我的应用程序有一个Rest 余烬模型重新适应嵌套端点,rest,ember.js,nested,endpoint,ember-model,Rest,Ember.js,Nested,Endpoint,Ember Model,我正在使用Ember 1.5构建一个web应用程序,并使用Ember Model 0.0.11将该应用程序链接到API。我目前在让Ember模型使用嵌套API端点方面遇到了问题 例如,我的应用程序有一个用户模型,它与Post模型有很多关系。现在,当我想为某个用户加载帖子时,我想要Post.findQuery('user\u id',{user\u id})方法访问GET/users/{user\u id}/posts端点。相反,Ember模型解决方案似乎更喜欢将查询作为参数发送到GET/post
用户
模型,它与Post
模型有很多关系。现在,当我想为某个用户加载帖子时,我想要Post.findQuery('user\u id',{user\u id})
方法访问GET/users/{user\u id}/posts
端点。相反,Ember模型解决方案似乎更喜欢将查询作为参数发送到GET/posts
端点
Ember模型的
RESTAdapter
允许轻松定制,但在我开始编写一个完全定制的RESTAdapter
之前,我想知道是否有人已经这样做了,以及他们是如何解决问题的。我们处理嵌套API路由的解决方案是使用请求的负载返回链接哈希。如果您可以更改API输出,这就是目前的做法。例如,当请求工作区时,返回的JSON如下所示(请原谅转义字符):
该模型将链接定义为async具有许多关系,即DS.attr('projects',{async:true})
。从存储加载工作区时,不包括链接的项目。当您在任何其他地方使用{{{each workspace.projects}}
或workspace.get('projects')
时,ember data将向/v1/workspace/wrk_krVZWGaJ/projects/
发出get请求,而不是默认路径/projects/
。尼托,嗯
更多的细节
{
"data":
{
"object":"workspace",
"id":"wrk_krVZWGaJ",
"organization_name":"Legros, Klein and Boehm",
"workspace_name":"Legros, Klein and Boehm",
"workspace_path":"legros, klein and boehm",
"status":true,
"credit_production":7,
"credit_revision":16,
"links":{
"projects":"\/v1\/workspaces\/wrk_krVZWGaJ\/projects",
"productions":"\/v1\/workspaces\/wrk_krVZWGaJ\/productions",
"subscription":"\/v1\/workspaces\/wrk_krVZWGaJ\/subscription",
"assets":"\/v1\/workspaces\/wrk_krVZWGaJ\/assets",
"descriptions":"\/v1\/workspaces\/wrk_krVZWGaJ\/descriptions",
"roles":"\/v1\/workspaces\/wrk_krVZWGaJ\/roles",
"registrations":"\/v1\/workspaces\/wrk_krVZWGaJ\/registrations",
"users":"\/v1\/workspaces\/wrk_krVZWGaJ\/users"
}
}
}