我requirejs
domReady
在我的代码中使用插件,如下所示:
1.模块配置:
requirejs.config({
baseUrl:'scripts',
paths:{
async:'lib/plugins/async',
domReady:'lib/plugins/domReady'
}
});
2.实际模块
require(['domReady!','./gmaps','./gmaps_controls'],function(gmaps,controls){
//get mapdiv here by id
//create controls from controls module here...
});
我得到错误:
GET http://localhost:8180/lib/plugins/domReady.js 404 (Not Found) require.js:34
Uncaught Error: Script error for: domReady
http://requirejs.org/docs/errors.html#scripterror require.js:8
这是我在scripts
文件夹中的文件结构:
./lib:
plugins require.js
./lib/plugins:
async.js domReady.js
更新2:
我这样加载requirejs
:
<script type="text/javascript" data-main="scripts/gmaps_displayScenario" src="scripts/lib/require.js"></script>
这对我有用:
requirejs.config({
baseUrl:'scripts',
paths:{
async:'lib/plugins/async',
domReady:'lib/plugins/domReady'
}
});
require(['domReady!','./gmaps','./gmaps_geoJSON'],function(domReady,gmaps,geoJSON){
//code goes on
我这样做是因为我只将 jQuery 用于$(document).ready()
函数和ajax
调用......我不想为此加载整个库。但是,这并不像这里指定的那样工作。