How to set Arcgis Javascript dojoConfig relative p

2019-05-03 09:19发布

I am using Arcgis Javascript API. API is built on dojo toolkit. So I need to use dojo features in API. I am preparing dojo config file as following.

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'
    }]    
};

I created a bootstrapper.js like following.

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

    application.Run();
})

And index.html file is like this.

<!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>

My application is hosted on IIS and has addres like this htp://domain/Demo/Sample1/index.html

when I run application, this code giving error like following.

"NetworkError: 404 Not Found - http://js.arcgis.com/3.6/js/dojo/application/main.js" enter image description here

If I set bootstrapper.js file as following, problem is solwing.

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

    application.Run();
})

enter image description here

1条回答
干净又极端
2楼-- · 2019-05-03 09:56

Try to change your script order in index.html file. Your config settings should load before 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>
查看更多
登录 后发表回答