Ember.js 余烬路由:向导步骤的不同URL
用例:包含多个步骤的向导。最初使用Ember.js 余烬路由:向导步骤的不同URL,ember.js,Ember.js,用例:包含多个步骤的向导。最初使用{{partial currentStepTemplate}实现 我想重构它,使每个步骤都有一个单独的控制器。最初执行了{render currentStepTemplate controller=currentStepController}},但与{partial}不同,render不绑定到currentStepTemplate和currentStepController属性,并将它们用作原始字符串 我创建了一个路由/walkthrough/:step 问题是
{{partial currentStepTemplate}
实现
我想重构它,使每个步骤都有一个单独的控制器。最初执行了{render currentStepTemplate controller=currentStepController}}
,但与{partial}
不同,render不绑定到currentStepTemplate
和currentStepController
属性,并将它们用作原始字符串
我创建了一个路由/walkthrough/:step
问题是路线上没有要加载的特定模型,但我需要知道使用:step
参数渲染哪个模板,该参数只能在模型
钩子中访问
将模型用作将步骤
参数进一步传递给设置控制器
和渲染模板
的一种方式,这看起来不是一种好的模式,但我不确定如何才能实现这一点
App.WalkthroughRoute = Ember.Route.extend(
steps: ["", "intro", "name", "photo", "create_course"]
model: (params) ->
@set('stepName', params['step'])
@set('stepTemplate', "walkthrough/teacher/_step_#{stepName}")
# Optional controller: used only if exists
if @container.lookup("controller:#{controllerName}")
@set('stepController', controllerName)
return @steps.indexOf(params['step'])
renderTemplate: (controller, model) ->
@render()
@render @get('stepTemplate'),
controller: @get('stepController')
into: 'walkthrough'
actions:
nextStep: ->
step = @modelFor('walkthrough')
@transitionTo('walkthrough.teacher', @steps[step + 1])
prevStep: ->
step = @modelFor('walkthrough')
@transitionTo('walkthrough.teacher', @steps[step - 1])
)
有什么提示/想法吗?谢谢 我敢肯定,您正在尝试重新创建路由器的工作方式。我会将每一步移动到资源下的路线。那么您的url将如下所示:
#/walkthrough/step1
#/walkthrough/step2
#/walkthrough/step3
#/walkthrough/step4
用路由器之类的
App.Router.map(function() {
this.resource('walkthrough', function(){
this.route('step1');
this.route('step2');
this.route('step3');
this.route('step4');
});
});