如何设置Arcgis Javascript dojoConfig包的相对路径

bar*_*oma 5 javascript dojo arcgis-js-api

我正在使用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'
    }]    
};
Run Code Online (Sandbox Code Playgroud)

我创建了一个bootstrapper.js,如下所示.

require(["application/main", "dojo/domReady!"], function (application) {
    console.log("bootstrapper is running");

    application.Run();
})
Run Code Online (Sandbox Code Playgroud)

而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>
Run Code Online (Sandbox Code Playgroud)

我的应用程序托管在IIS上,并且有像这样的地址:htp://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();
})
Run Code Online (Sandbox Code Playgroud)

在此输入图像描述

bay*_*ncu 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>
Run Code Online (Sandbox Code Playgroud)