以ember创建新资源 [英] Creating a new resource in ember
问题描述
- 选择访问
- 选择你看到的人
- 确认
该应用程序还允许管理员查看所有访问并查看个人访问。
我有访问$我已经使用Ember Data连接到服务器的c $ c>和
Person
模型。这是我的路线如下所示:
App.Router.map() - >
@resource'visits', - >
@resource'visit',{path:'/:visit_id'}
@resource'new', - >
@route'welcome'
@route'目录'
@route'谢谢'
这允许我在 VisitsNewRoute
中创建一个新的访问
模型,并在欢迎
,目录
和感谢
视图。
这个工作。但是,有一个新的
资源感觉是错误的,特别是因为可以想象,我至少需要一个新的
路由在我的应用程序。
有更好的方法吗?
我认为您可以将新的
资源更改为 newVisit
,如下所示:
App.Router.map() - >
@resource'visits', - >
@resource'visit',{path:'/:visit_id'}
@resource'newVisit', - >
@route'welcome'
@route'目录'
@route'谢谢'
现在您将有一个 NewVisitRoute
,您可以在其中创建一个新的访问
模型以在每个的小路线。
您将能够使用路由名称转换到此路由: newVisit.welcome
, newVisit.directory
和 newVisit.thanks
。您可以在链接到
帮助链接中使用此路由名称:
{{link-toWelcome,newVisit.welcome}}
I'm building an office reception app in Ember. When a person arrives at the office, they pop open the app and are taken through a three step wizard:
- Choose a reason for visiting
- Choose the person you've come to see
- Confirm
The app also allows an administrator to view all of the visits and to view an individual visit.
I have Visit
and Person
models I've hooked up to a server using Ember Data. Here's what my routes look like:
App.Router.map () ->
@resource 'visits', ->
@resource 'visit', { path: '/:visit_id' }
@resource 'new', ->
@route 'welcome'
@route 'directory'
@route 'thanks'
This allows me to create a new Visit
model in the VisitsNewRoute
and use it in the welcome
, directory
and thanks
views.
This works. However, it feels wrong to have a new
resource, especially since it's conceivable I'll want at least one more new
route in my application.
Is there a better way to do this?
I think that you can change the new
resource to newVisit
like this:
App.Router.map () ->
@resource 'visits', ->
@resource 'visit', { path: '/:visit_id' }
@resource 'newVisit', ->
@route 'welcome'
@route 'directory'
@route 'thanks'
Now you will have a NewVisitRoute
where you can create a new Visit
model to use in each of the child routes.
And you will be able to make a transition to this routes with the route names: newVisit.welcome
, newVisit.directory
and newVisit.thanks
. You can use this route names in a link-to
helper link this:
{{link-to "Welcome", "newVisit.welcome"}}
这篇关于以ember创建新资源的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!