我需要创建一个包含多个步骤的向导。每一步都会显示一个带有选项的表单,并且根据用户的选择,向导应该转到某个步骤,并将用户首选项(选择)保存在某个地方。
这些首选项不会保存在模型中,它们仅与模型创建步骤相关。
为了给出一些上下文,这样做的目标是:
问题是,在 Ember 中实现这一目标的最佳方式是什么?
这是我的——Ember 新手——的想法:
outlets
中,应根据当前步骤动态呈现。 这是我完全迷失的地方。这该怎么做?每个步骤是否应该有不同的路线? 正在使用的版本:
最佳答案
听起来你是在正确的轨道上。
Create a template for each wizard step.
是的,这是一个好的开始。
Keep track of the current step. Where? Controller? Route?
Controller 或路由都可以工作。如果您想要为每个步骤和后退/前进工作添加书签网址,路由最有意义,并且可能是最直接的解决方案。将假设您已选择路线。
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 将负责自动渲染适当的模板。
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.
将“完成”视为又一步。每个步骤都有自己的 Controller ,用于记录用户响应。最后一个 Controller 使用“需要”来访问较早的 Controller ,以便根据对向导的响应自定义行为。
关于model-view-controller - Ember.js - 创建一个多步骤向导 - 如何?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15383834/