简体   繁体   English

Ember.js使用路由器架构获取父路由的控制器

[英]Ember.js get controller of parent route using Router architecture

If I have an application using the Router architecture , how do I get the controller of the parent route? 如果我有一个使用路由器架构的应用程序,我如何获得父路由的控制器?

suppose a route like 假设有一条路线

Router: Ember.Router.extend 
    enableLogging: true
    root: Ember.Route.extend
        main: Ember.Route.extend
            route: '/'
            connectOutlets: (router, event) ->
                 router.get('applicationController').connectOutlet('main')
            editor: Ember.Route.extend
                route: '/editor'
                connectOutlets: (router, event) ->
                    router.get('mainController').connectOutlet('editor')

So how would my EditorController get a hold of my MainController ? 那么我的EditorController将如何获得我的MainController

I've tried @get('parentController') , @get('parent') , and @get('controller') with no success 我试过@get('parentController')@get('parent')@get('controller')没有成功

You can access the router through the target property of a controller. 您可以通过控制器的target属性访问路由器。

eg, in your case, from any controller: 例如,在您的情况下,来自任何控制器:

@get('target.mainController')

Or, if you do not use head revision of Ember: 或者,如果您不使用Ember的头部修订版:

@getPath('target.mainController')

According to my understanding, an application is supposed to have only one router, so why dont we just do: 根据我的理解,应用程序应该只有一个路由器,所以为什么我们不这样做:

@get('App.router.mainController')

I have no idea on what is the right approach! 我不知道什么是正确的方法! I feel like 'target' is storing the object to which actions or events are dispatched. 我觉得'target'是存储调度动作或事件的对象。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM