8

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,当我输入代码时,它会出现与上面提到的相同的错误。

谢谢!

4

2 回答 2

17

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

因此,order 插件已被删除,并且在 Tim Branyen 和 Dave Geddes 的领导下,分别使用和 wrap,requirejs 2.0 直接在 requirejs 中集成了这种依赖树规范。

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

此外,请查看shimRequireJS 站点上的文档 - http://requirejs.org/docs/api.html#config-shim

于 2012-05-31T23:11:58.120 回答
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();
    });
});
于 2012-06-01T00:01:25.533 回答