2012-03-16 83 views
0

您好已經開始開發一個應用程序使用emberjs到目前爲止所有東西都很好,但我注意到一件事,當我刷新網頁沒有任何顯示的時候,我得到以下錯誤瀏覽器控制檯: 遺漏的類型錯誤:無法讀取屬性「layoutStates」不確定的 - 燼 - layout.jsEmberjs佈局錯誤

如果我刷新頁面再次錯誤消失,

爲什麼會出現這個錯誤? 如何阻止這種錯誤發生?

在此先感謝...的要求

App.routeManager = em.RouteManager.create({ 
    rootView: App.main, 
    home: em.LayoutState.create({ 
     selector: '.inbox', 
     viewClass: App.InboxView, 
     enter: function (stateManager, transition) { 
      this._super(stateManager, transition); 
     } 
    }), 
    View2: em.LayoutState.create({ 
     route: 'contacts', 
     selector: '.contacts', 
     viewClass: App.ContactsView, 
     enter: function (stateManager, transition) { 
      this._super(stateManager, transition); 
     } 
    }), 
    View3: em.LayoutState.create({ 
     route: 'account', 
     selector: '.account', 
     viewClass: App.AccountView, 
     enter: function (stateManager, transition) { 
      this._super(stateManager, transition); 
     } 
    }) 
}); 

錯誤

路徑管理代碼恰好燼-layouts.js線126

init: function() { 
    // This is currently experimental. We allow 
    // the view itself to define it's substates 
    // for better encapsulation. To do this, set 
    // the layoutStates property. 
    var viewClass = get(this, 'viewClass'); 
    if(viewClass) { 
     var layoutStates = get(viewClass, 'proto').layoutStates; 
     set(this, 'states', layoutStates); 
    } 

    this._super(); 
    }, 
+0

你可以添加你的RouteManager代碼嗎? – louiscoquio 2012-03-16 12:13:37

+0

@louiscoquio RouteManager代碼請求 – user655261 2012-03-20 10:51:45

+0

我在這裏沒有看到任何問題。是否確定App.main在創建RouteManager之前已設置,並且在創建主體後添加到主體?如果你不知道,你可以添加插入App.main視圖的主html頁面嗎? – louiscoquio 2012-03-20 12:12:16

回答

0

發現問題到這一點,與餘燼佈局無關,它與要求js有關。在文件的頂部,我必須用define來取代require,其解釋在require js api文檔http://requirejs.org/docs/api.html中。

//------THIS ONE IS WRONG AND CAUSES THE ERROR ------------------ 
require(['../../lib/ember/load-ember','model/notificationModel'], 
     function (em, notification) {}); 


//Changing to define has fixed the problem in all browsers 
define(['../../lib/ember/load-ember','model/notificationModel'], 
     function (em, notification) {}); 
0

我得到了同樣的錯誤,但我沒有使用requirejs。

我在想我的問題是版本問題。我使用的是ember-0.9.5.js。我搜索了,原型功能似乎從這個版本中刪除。 proto()在以前的版本中確實存在。這似乎是解決這個問題

VAR layoutStates = viewClass.prototype.layoutStates

燼的佈局明確要求上線29

var layoutStates = viewClass.proto().layoutStates; 

更改此行此功能;