我正在使用Arcgis Javascript API。 API基于dojo工具包构建。所以我需要在API中使用dojo功能。我正在准备dojo配置文件如下。
var pathRegex = new RegExp("/\/[^\/]+$/");
var locationPath = location.pathname.replace(pathRegex, '');
var dojoConfig = {
async: true,
parseOnLoad: false,
baseUrl:"js/",
packages: [
{
name: "application",
location: locationPath + '/js/application'
}]
};
我创建了一个类似于bootstrapper.js。
require(["application/main", "dojo/domReady!"], function (application) {
console.log("bootstrapper is running");
application.Run();
})
index.html文件是这样的。
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Arcgis Javacsript API Samples</title>
<link rel="stylesheet" href="http://serverapi.arcgisonline.com/jsapi/arcgis/3.5/js/dojo/dijit/themes/claro/claro.css">
<link rel="stylesheet" href="http://serverapi.arcgisonline.com/jsapi/arcgis/3.5/js/esri/css/esri.css">
</head>
<body class="claro">
<div id="map"></div>
<script src="//js.arcgis.com/3.6/"></script>
<script src="js/application/djConfig.js"></script>
<script src="js/application/bootstrapper.js"></script>
</body>
</html>
我的应用程序托管在IIS上,并且有像这样的地址:http://domain/Demo/Sample1/index.html
当我运行应用程序时,此代码会产生如下错误。
“NetworkError:404 Not Found - http://js.arcgis.com/3.6/js/dojo/application/main.js”
如果我将bootstrapper.js文件设置如下,问题就是解决。
require(["js/application/main.js", "dojo/domReady!"], function (application) {
console.log("bootstrapper is running");
application.Run();
})
答案 0 :(得分:5)
尝试在index.html文件中更改脚本顺序。您的配置设置应在CDN之前加载。
<div id="map"></div>
<script src="js/application/djConfig.js"></script>
<script src="//js.arcgis.com/3.6/"></script>
<script src="js/application/bootstrapper.js"></script>
</body>