Ember js从之前的路线获得物体

时间:2017-01-05 17:00:04

标签: ember.js

我正在构建我的第一个EmberJS应用程序。

最初从索引路由开始,我将显示A.当用户单击A时,它将路由到/a。组件A将有一个字段url,在填写并单击按钮后,它将路由到/b。组件B还有一个现场电子邮件。填写并单击一个按钮,它将路由到/summary,显示我在A和B中填写的内容。如何在最佳实践中完成?

我正在使用ember-clithis.transitionTo(/b)前往路线/b

2 个答案:

答案 0 :(得分:2)

看起来嵌套路线对这种实现有好处 / a - 路线

model(){
 return {url:'default'};
}

a.hbs

{{comp-a model=model}}

/ a / b - 路线

model(){
 return {email:''};
}

A / b.hbs

{{comp-b model=model}}

/ a / b / summary - route

model(){
 return {amodel:this.modelFor('a'),bmodel:this.modelFor('b')};
}

A / B / summary.hbs

{{comp-a model=model.amodel }}
{{comp-b model=model.bmodel }}

答案 1 :(得分:1)

这是一个教程,可以准确地解释如何制作像您要求的多步骤表单。 http://romulomachado.github.io/2016/12/06/multi-step-form-with-ember.html

使用嵌套路由系统,这是非常简单的。

Router.map(function() {
  this.route('checkout', function() {
    this.route('personal-info');
    this.route('shipping-info');
    this.route('payment-info');
    this.route('confirmation');
  });
});

然后你可以使用'order'或某种'form'模型来保持信息的活跃。

我按照这个例子构建了一个能够在最后编辑和确认的能力。 :)