最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Ember.js get controller of parent route using Router architecture - Stack Overflow

programmeradmin1浏览0评论

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?

I've tried @get('parentController'), @get('parent'), and @get('controller') with no success

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?

I've tried @get('parentController'), @get('parent'), and @get('controller') with no success

Share Improve this question edited Jan 14, 2013 at 21:36 sly7_7 12k3 gold badges41 silver badges54 bronze badges asked Jul 26, 2012 at 18:21 wmarbutwmarbut 4,7057 gold badges45 silver badges76 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 6

You can access the router through the target property of a controller.

e.g, in your case, from any controller:

@get('target.mainController')

Or, if you do not use head revision of 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.

发布评论

评论列表(0)

  1. 暂无评论