在我的应用程序中,我可以从应用程序的任何位置选择“组”模型。将所有组加载到应用程序的模型挂钩中,然后将selectedGroup保存为应用程序控制器中的属性。
许多路由具有依赖于selectedGroup的模型,因此当选择新组时,我需要重新加载当前路由。从我能够阅读的内容来看,实现这一目标的最佳方法就是转换到路径。
这是最好的做事方式吗?我如何获得当前路线,然后重新过渡到它。
如果需要进一步说明,请发表评论!谢谢!
修改
可能的路线代码:
needs: ['application'],
model: function() {
var groupID = this.controllerFor('application').get('activeClass.id');
return this.store.find('student', { group: groupID });
}
答案 0 :(得分:1)
您可以从应用程序控制器获取currentRoute
。由于selectedGroup
也保存在应用程序控制器上,因此您可以向其中添加一个观察者并在其中进行转换。代码看起来像。
App.ApplicationController = Em.Controller.extend({
selectedGroup: '',
onSelectionChange: function() {
var currentRoute = this.get('currentRouteName');
this.transitionToRoute(currentRoute);
}.observes('selectedGroup')
});