RequireJS插件(order.js)

时间:2012-05-31 21:26:59

标签: javascript requirejs

http://requirejs.org/

我最近下载了require.js 2.0,我的控制台出现错误:

Uncaught TypeError: Object function (){var g=ga.call(arguments,0),e;if(f&&v(e=g[g.length-1]))e.__requireJsBuild=!0;g.push(d);return b.apply(null,g)} has no method 'nameToUrl'

requirejs是否仍然支持order.js插件?我没有在网站上看到它的文档。

当我尝试删除文件时,脚本会中断。

在我的索引文件中,我在head部分包含了requirejs脚本:

<!DOCTYPE html>
<html>
    <head>
        <title>
            My Mobile Application
        </title>
        <link rel="stylesheet" href="http://code.jquery.com/mobile/1.1.0/jquery.mobile-1.1.0.min.css" />
        <link rel="stylesheet" href="public/css/style.css" />
        <script data-main="scripts/main.js" src="scripts/require.js"></script>
    </head>
    <body></body>
</html>

然后在我的main.js文件中:

requirejs.config({
    //By default load any module IDs from js/lib
    baseUrl: 'js/lib',
    //except, if the module ID starts with "app",
    //load it from the js/app directory. paths
    //config is relative to the baseUrl, and
    //never includes a ".js" extension since
    //the paths config could be for a directory.
    paths: {
        app: '../app',
        assets: '../assets',
        views: '../app/views',
        templates: '../app/templates',
        collections: '../app/collections',
        models: '../app/models'
    }
});

// Start the main app logic.
requirejs([
    'jquery/jquery',
    'assets/jqm.config',
    'jquery/mobile',
    'text'
]);

require([
    'app'
    ],
    function( App ){
        $(document).ready( function(){
            App.initialize();
        });
    }
);

我认为App.initialize没有任何错误,App.initialize正在做的只是简单的地理位置。 requirejs只是询问order.js,当我输入代码时,它具有与上述相同的错误。

谢谢!

2 个答案:

答案 0 :(得分:17)

您不再支持order的假设是正确的。它已删除,以支持shim配置选项:

  

因此,订单插件已被删除并遵循   分别使用和包装的Tim Branyen和Dave Geddes需要js   2.0直接在requirejs中集成了那种依赖树规范。

需要2.0升级说明 - https://github.com/jrburke/requirejs/wiki/Upgrading-to-RequireJS-2.0

另外,请查看RequireJS网站上的shim文档 - http://requirejs.org/docs/api.html#config-shim

答案 1 :(得分:2)

哦想通了。

//This is our main applicatoon boot loader or bootstrap
//here we are loading necessary scripts dependencies like
//jquery, jqm.config, mobile, text


requirejs.config({
    baseUrl: 'js/libs',
    //except, if the module ID starts with "app",
    //load it from the js/app directory. paths
    //config is relative to the baseUrl, and
    //never includes a ".js" extension since
    //the paths config could be for a directory.
    paths: {
        app: '../app',
        assets: '../assets',
        views: '../app/views',
        templates: '../app/templates',
        collections: '../app/collections',
        models: '../app/models'
    }
});

// Start the main app logic.

require(["jquery","assets/jqm.config","jquery/mobile","text","app"], 
    function(
    $,
    config,
    mobile,
    text,
    App
    ) {
    //the jquery.alpha.js and jquery.beta.js plugins have been loaded.
    $(function() {
        App.initialize();
    });
});