3

此问题仅出现在 Internet Explorer 9 中,适用于 Chrome 和 Firefox。

这是我加载所有依赖项的主文件:

// Filename: main.js

// Require.js allows us to configure shortcut alias
// There usage will become more apparent futher along in the tutorial.
require.config({
    paths: {
        jQuery: 'libs/jquery/jquery',
        Underscore: 'libs/underscore/underscore',
        Backbone: 'libs/backbone/backbone',
        JSON: 'libs/json2/json2',
        templates: '../templates'
    }

});

require([
    // Load our app module and pass it to our definition function
    'order!app',

    // Some plugins have to be loaded in order due to there non AMD compliance
    // Because these scripts are not "modules" they do not pass any values to the definition function below
    'order!libs/jquery/jquery-min',
    'order!libs/underscore/underscore-min',
    'order!libs/backbone/backbone-min',
    'order!libs/json2/json2-src'
], function(App){
    // The "app" dependency is passed in as "App"
    // Again, the other dependencies passed in are not "AMD" therefore don't pass a parameter to this function
    App.initialize();
});

这是浏览器崩溃的地方:

SomeRoute:function(){
    facade.console.log("SomeRoute");
    $("#toDelete").remove();
    this.user =  new User($.cookies.get('User'));
    var that = this;
    require(['views/SomeView'],function(SomeView){    // On this require
        if(that.user.get('usr_id') > 0){
            var view = new SomeView();
            $("#domelement").append(that.changeView(view));
        }
        else window.location = APP_URL + "/login#login";
    });
}

当我走这条路线时,我收到了这个错误:

SCRIPT5022: Load timeout for modules: views/SomeView 
http://requirejs.org/docs/errors.html#timeout 
require.js, Line 27 Char 311

但是 Chrome 或 Firefox 中什么都没有出现,一切正常。

编辑:此外,刷新我要求加载的页面非常好。只有在我走路线的时候。我必须刷新才能访问我的其他模块内容。

编辑 2:经过一些额外的测试后,我尝试将“enforceDefine:true”添加到我的 main.js 并更改了我的 require 调用。没有改变。此外,使用此函数调用的任何视图...

        confirmView: function(idDialog, view, opts1){
            facade.loader("body");
            require(["text!templates/common/dialog/confirm.phtml"], function(dialogTp){
                var opts = $.extend({}, facade.dialog.defaultOpts, opts1);
                // Delete previous dialog with same ID
                $("#"+idDialog).remove();

                // select the view we'll set
                var el = "#"+idDialog+" .modal-body";

                // Create our template with our options
                var contentDialog = _.template(dialogTp, { "option": opts, "text": "", "id": idDialog});
                $("body").append(contentDialog);

                require([view], function(viewClasse){
                    viewClasse.setElement("#"+idDialog+" .modal-body");
                    opts.preLoad(viewClasse);
                    viewClasse.render();

                    facade.unloader("body");

                    // twitter modal instance
                    facade.dialog.events(idDialog, opts, viewClasse);
                    $("#"+idDialog).modal(opts.modal);
                });
            });
        }

...也会崩溃(超时)。

我真的不知道发生了什么...

谢谢你的帮助。

4

1 回答 1

2

我之前遇到过这个问题,它源于尝试使用order普通模块,而不是脚本。从旧的 1.0.x 文档:

订单插件最好与传统脚本一起使用。使用 define() 定义模块的脚本不需要它。可以混合搭配“订单!” 具有常规依赖项的依赖项,但只有“顺序!” 将按照彼此的相对顺序进行评估。

http://requirejs.org/docs/1.0/docs/api.html#order

在任何情况下,您都应该使用 RequireJS 2.0,它取消了 order 插件以支持shimconfiguration

于 2012-07-26T13:10:32.800 回答