gpt4 book ai didi

ember.js - Ember : Get route instance from the controller

转载 作者:行者123 更新时间:2023-12-02 14:13:11 24 4
gpt4 key购买 nike

我有一个多步骤流程,用户可以按顺序执行或直接跳转到一个部分(如果中间的部分已完成)。我认为这个逻辑应该在Route对象中。但是,从 Controller 内部,如何访问路由实例。例如,最好能够在 Controller 中执行以下操作:

App.Flow = Em.ObjectController.extend({
submit: function(){
// Validation and XHR requests
// ...

// Go to the next step
route.goToNextStep();
}
}

最佳答案

在 Controller 中,您可以通过 this.get('target') 访问路由器。所以 this.get('target').send('goToNextStep') 应该可以工作。

像这样:

App.Flow = Em.ObjectController.extend({
submit: function(){
// ...
this.get('target').send('gotoNextStep');
}
}

App.FlowRoute = Ember.Route.extend({
events: {
gotoNextStep: function(){
// ...
this.transitionTo(routeName);
}
}
}

关于ember.js - Ember : Get route instance from the controller,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17459195/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com