2012-09-17 171 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