2014-12-07 170 views
1

完全有可能我不完全理解進入路由時控制器的實例化順序,但我試圖在我的ApplicationRoute中獲取currentPathbeforeModel並掙扎。奇怪的是,當我登錄的路線,我可以看到一個名爲controller在其財產...在ApplicationRoute中獲取當前路徑

enter image description here

beforeModel: function(transition) { 

    console.log(this); 
    console.log(this.controller); // undefined 
    console.log(this.get('controller')); // undefined 

    // this too 
    console.log(this.controllerFor('application')); 
    console.log(this.controllerFor('application').currentPath); // undefined 
    console.log(this.controllerFor("application").get("currentPath")); // undefined 

}, 

this.controller是不確定的。正如你在日誌輸出中看到的那樣,currentPath的確在該屬性上設置,這就是我想要的!

我注意到,controller顯然沒有定義,直到路由器實例化了控制器。所以documentation有點清楚,因爲在willTransition,this.controller定義。

控制器屬性似乎在setup定義,所以我很困惑,我怎麼能看到它在beforeModel。我如何獲得currentPathbeforeModel in ApplicationRoute

回答

0

原來,console.log與對象返回對所述對象的引用。所以它不是日誌時對象的快照。

This little trick登錄時,讓我的狀態對象:

console.log($.extend({}, this)); 
相關問題