以ember创建新资源 [英] Creating a new resource in ember

查看:123
本文介绍了以ember创建新资源的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在Ember建立办公室接待应用程序。当一个人到达办公室时,他们弹出应用程序,并通过三步骤向导:




  • 选择访问

  • 选择你看到的人

  • 确认



该应用程序还允许管理员查看所有访问并查看个人访问。



我有访问 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屋!

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