Ember.js - 创建一个多步骤向导 - 如何? [英] Ember.js - Creating a multistep wizard - How to?

查看:80
本文介绍了Ember.js - 创建一个多步骤向导 - 如何?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要创建一个带有多个步骤的向导。每个步骤都将显示一个带有选项的表单,并且根据用户的选择,向导应该进入一定的步骤,并保留用户偏好(选择)存储在某些地方。

I need to create a wizard with multiple steps. Each step will display a form with options, and depending on the user choices, the wizard should go to a certain step, as well as keeping user preferences (choices) stored in some place.

这些首选项不保存在模型中,它们仅与模型创建步骤相关。

These preferences are not saved in the model, they are only relevant to the step of model creation.

为了给出一些上下文,这个目标是:

In order to give some context, the goal of this is:


  • 让用户对他的业务开放时间有几个问题。例如:周末是否开放?夏天是否有所不同?

  • 根据这些问题的答案,将显示一个最终的表格来创建时间表模型。

问题是,这将是最好的在Ember中完成这个工作的方法?

The question is, which would be the best way to accomplish this inside Ember?

这是我的-Ember newbie-想法:

Here are my –Ember newbie– thoughts:


  • 为每个向导创建一个模板步骤。

  • 跟踪当前步骤。 在哪里?控制器?路线?

  • 将这些模板显示为出口,这些模板应根据当前步骤动态呈现。这是我完全迷路的地方。怎么办?每个步骤是否有不同的路线?

  • 跟踪控制器中的用户答案。

  • 一旦向导完成,加载表单模板,这将读取控制器中存储的用户首选项。

  • Create a template for each wizard step.
  • Keep track of the current step. Where? Controller? Route?
  • Display these templates into outlets, which should be rendered dynamically according to the current step. This is where I get completely lost. How to do this? Should each step have a different route or not?
  • Keep track of user answers in the controller.
  • Once the wizard is finished, load the form template, which will read user preferences stored in controller.

正在使用的版本:


  • Ember.VERSION:1.0.0-rc.1 application.js:9268

  • Handlebars.VERSION:1.0.0-rc.3 application.js:9268

  • jQuery.VERSION:1.9.1

推荐答案

听起来像是在正确的轨道上。

Sounds like you are on the right track.


为每个向导步骤创建一个模板。

Create a template for each wizard step.

是的,这是一个好的开始。

Yes, that is a good start.


跟踪当前步骤。哪里?控制器?路线?

Keep track of the current step. Where? Controller? Route?

控制器或路由将工作。如果您希望每个步骤都可以使用书签网址,并使后台/前端工作,路由最有意义,并且可能是最简单的解决方案。将假设您选择了路线。

Either controller or route would work. Route makes most sense if you want bookmarkable urls for each step and for back/forward to work and is probably the most straightforward solution. Will assume you've chosen route.


将这些模板显示为出口,这些模板应根据当前步骤动态呈现。这是我完全迷路的地方。怎么办?每个步骤是否有不同的路由?

Display these templates into outlets, which should be rendered dynamically according to the current step. This is where I get completely lost. How to do this? Should each step have a different route or not?

由于每一步都将是一条路线,因此,ember会自动处理渲染适当的模板

Since each step will be a route, ember will take care of rendering appropriate template automagically.


跟踪控制器中的用户答案。

Keep track of user answers in the controller.

一旦向导完成后,加载表单模板,这将读取控制器中存储的用户首选项。

Once the wizard is finished, load the form template, which will read user preferences stored in controller.

将完成视为另一步。每一步都得到自己的控制器,用于记录用户的响应。最后一个控制器使用需求来访问较早的控制器,以便根据向导的响应自定义行为。

Think of "finished" as just another step. Each step gets it's own controller which is used to record user responses. The last controller uses "needs" to access earlier controllers in order to customize behavior based on responses to the wizard.

这篇关于Ember.js - 创建一个多步骤向导 - 如何?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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