2014-11-21 66 views
0

我有嵌套的路線是這樣的:Emberjs:訪問動態段嵌套路由/控制器

this.resource('profile', { path: '/:user' }, function(){ 
    this.route('followers'); 
    this.route('following'); 
    }); 

我需要的「用戶」動態段在我的追隨者/以下路線/控制器的值的訪問。我想到的一種方法是使用

this.controllerFor('profile').get('user') 

在我的追隨者/追蹤路線中。

這樣做的正確方法是什麼?

感謝,

回答

0

我認爲你正在尋找route#modelFor

實施例:

App.Router.map(function() { 
    this.resource('post', { path: '/post/:post_id' }, function() { 
     this.resource('comments'); 
    }); 
}); 

App.CommentsRoute = Ember.Route.extend({ 
    afterModel: function() { 
     this.set('post', this.modelFor('post')); 
    } 
});