2013-08-19 26 views
1

我想存儲與任何路由關聯的自定義參數;是否有可能將它們存儲在路由器映射中?例如:存儲在Ember路由器中的參數

this.route('aboutUs', {path: 'about-us', langIndex: '1'}); 

然後我該如何從控制器中恢復langIndex值?

回答

2

路由器地圖不是用來存儲您以後在控制器中需要的瞬態數據。對於像您的使用情況下工作,你應該做的,而像這樣:

App.AboutUsRoute = Ember.Route.extend({ 
    langIndex: '1' 
    ... 
}); 

,然後得到相應路由控制器裏面,你可以得到你的變量,如:

App.AboutUsController = Ember.ObjectController.extend({ 
    someMethod: function() { 
    // get here the variable stored in your route 
    // this.get('target') always refers to the controller 
    // corresponding route 
    this.get('target').get('langIndex'); 
    } 
}); 

希望它能幫助。

+0

是的謝謝你澄清這一點 –