我在我的代码中使用requirejs
domReady
插件,如下所示:
1.Config for module:
requirejs.config({
baseUrl:'scripts',
paths:{
async:'lib/plugins/async',
domReady:'lib/plugins/domReady'
}
});
2.Actual module
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
我像这样加载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
我这样做是因为我只对$(document).ready()
函数使用jQuery并进行ajax
调用...我不想为此加载整个库。 However this is not working as specified here