2012-09-17 198 views
1

其實我正面臨Requirejs和Backbone的煩人問題。 我發展我的應用程序在兩個不同的路徑:Requirejs:模塊加載超時

  1. 主體准入,例如:/App/index.php#list
  2. 次訪問,例如:/App/index.php/克隆#列表

當我需要使用方法require([module])加載模塊時,會出現此問題。

如果我使用絕對路徑,像require(['/App/js/views/modal.js'])我剛剛得到這個錯誤:

Error: Load timeout for modules: /App/js/views/modal.js

http://requirejs.org/docs/errors.html#timeout

如果我用一種相對的方式,像require(['js/views/modal.js'])我的主要通道和require(['../js/views/modal.js'])我個子訪問,一切都按預期方式工作。

我正在加載其他模塊的絕對路徑,他們的工作,如果我複製模塊,並要求它與一個不同的名稱,它的工作,我唯一的區別是,我要求的模塊已被確定在另一個模塊,所以它已經被加載,這樣的:

主模塊

require('/App/js/views/row.js'], function(Row){ 
    Somecode... 
}); 

.... 

require('/App/js/views/modal.js'], function(Modal){ 
    Othercode... 
}); 

行模塊

define([ 
'backbone', 
'text!templates/row.html', 
'views/modal', //the same view callend in my main file! 
], function(Backbone, rowTemplate, Modal){ 
    Viewcode... 
}); 

模態模塊

define([ 
'backbone', 
'text!templates/modal.html', 
'models/user_model', 
], function(Backbone, modalTemplate, Model){ 
    Viewcode... 
}); 

也許我失去了一些東西,但我不明白這背後的邏輯,爲什麼不帶絕對地址的工作?

回答

1

在require.js中,您不需要將.js追加到文件名的末尾,我自己也看到了奇怪的行爲。另外,我建議你在你的應用程序的各個模塊中使用相對路徑,因爲它可以使應用程序的模塊/組件更容易地拖放到另一個應用程序中。

+0

感謝您的建議,我已經通過使主訪問看起來與次要文件('/ App/index.php/main#list')相同來解決這個問題,所以我可以使用相對路徑。 – Ingro

+0

所以這是'paths'或'baseUrl'配置參數中的錯誤配置?請標記正確的答案然後創建您自己的答案並將其標記。只是不要讓這個問題像這樣掛起來。 – hcpl