dojoConfig是:
<script type="text/javascript">
dojoConfig = {
async: true,
parseOnLoad: false,
packages: [
{ name: 'jquery', location: '//ajax.googleapis.com/ajax/libs/jquery/3.1.1', main: 'jquery.min' },
{ name: 'jqueryui', location: '//ajax.googleapis.com/ajax/libs/jqueryui/1.12.1', main: 'jquery-ui.min' }
]
};
</script>
我从google加载:
以下将演示此问题:
<script type="text/javascript">
define.amd.jQuery = true;
require(["jquery", "dojo/domReady!"], function (jquery) {
$(document).ready(function () {
console.log("First ready!"); //works
});
});
$(document).ready(function(){console.log("ready!");});//throws error
</script>
这似乎是一个计时问题,因为Uncaught ReferenceError:未定义$是在“First ready!”之前写入控制台的。写出来了。想要使用任何一个就绪功能。有关如何解决的任何想法?如果没有,那么我们可以在dojo / ready函数中包装所有根级别$函数,但有点蠢。
答案 0 :(得分:1)
您获得$ undefined
因为正确加载了jquery并且无法直接在您的dojoConfig
中使用cdn版本asfaik。
要解决此问题,最简单的方法是尝试在您的html <header>
中添加来自cdn添加脚本标记的jquery:
<header>
<script src="//ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
<script src="//ajax.googleapis.com/ajax/libs/jqueryui/1.12.1/jquery-ui.min.js"></script>
</header>
或者你可以尝试将jquery加载为非amd模块模块,如dojo文档中所述:
https://dojotoolkit.org/documentation/tutorials/1.10/modules_advanced/
相反,如果你不使用cdn,你可以尝试以下方法:
<!-- any external libraries configuration included in header -->
<!-- dojo config -->
<script>
var dojoConfig = {
baseUrl: "./",
async: true,
isDebug: true,
parseOnLoad: false,
packages: [
{name: "dojo", location: "libs/dojo"},
{name: "dijit", location: "libs/dijit"},
{name: "dojox", location: "libs/dojox"},
{name: "jquery", location: "libs/jquery", main: "jquery-3.1.1"},
{name: "jqueryui", location: "libs/jquery", main: "jquery-ui-1.12.1"},
]
};
</script>