【问题标题】:RequireJS plugin( order.js )RequireJS 插件( order.js )
【发布时间】:2012-05-31 21:26:59
【问题描述】:

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

谢谢!

【问题讨论】:

标签: javascript requirejs


【解决方案1】:

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

因此,订单插件已被删除并遵循 Tim Branyen 和 Dave Geddes,分别是 use 和 wrap,requirejs 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

【讨论】:

  • 好的,非常感谢,这确实是一个很大的帮助。现在将尝试并让您知道它是否有效:)
  • 顺便说一句,我正在使用 jQuery,之前我从给定的链接下载了 link 一个文件,我使用的是 require-jquery.js 而不是 require.js,现在我收到此错误:插件未定义。调试各种错误非常困难。
  • 在 chrome 的检查元素中,我收到此错误:Cannot read property 'normalize' of undefined 。叹息*
  • 非常有用,目前还不知道 shim!
【解决方案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();
    });
});

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2015-04-21
    • 1970-01-01
    • 1970-01-01
    • 2012-10-23
    • 2014-03-05
    • 1970-01-01
    • 1970-01-01
    • 2013-11-28
    相关资源
    最近更新 更多