无法使requirejs与mvc4一起工作

时间:2013-05-17 11:30:46

标签: jquery requirejs

我试图从需要js开始...以下是我尝试使用的最基本的例子....

我已经定义了“jquery”& “jqueryui”使用require js并提供了jqueryui对jquery的依赖.......

根据文档..下面必须工作,我必须得到jquit ...但警报框说jqui是未定义....

我的代码有什么问题?

<script type="text/javascript" src="/Scripts/require.js"></script>
<script type="text/javascript">
    // Configure the RequireJS paths to use an alias for the jQuery library.
    requirejs.config({
        paths: {
            "jquery": "./Scripts/jquery-1.8.2",
            "jqueryui": "./Scripts/jquery-ui-1.8.24"
        },
        shim: {
            "jqueryui": ["jquery"]
        }
    });
    // Now that we have configured a named alias for the jQuery library, 
    // let's try to load it using the named module.
    requirejs(["jquery", "jqueryui"], function(jq, jqui) {
        // Log the callback parameter.
        console.log("jq.fn.jquery:", jq.fn.jquery);
        alert(jqui);
    });
</script>

1 个答案:

答案 0 :(得分:0)

这基本上是正确的。但是,您需要通过主jquery对象引用ui插件。没有单独的UI“模块”。因此:

requirejs(["jquery", "jqueryui"], function(jq) { // Note! one parameter
    // Log the callback parameter.
    console.log("jq.fn.jquery:", jq.fn.jquery);
    alert(jq.fn.button); // Note! The UI plugin is loaded!
});