Arcgis (ESRI) dojo calling multipleDefine with a component using define for jQuery

I want to include a component written by someone in my ArcGIS web application.

However, when I turn it on, I always encounter the multipleDefine problem in the console window.

There are two ways to solve this problem by moving the script below the component.

<script src="https://js.arcgis.com/3.14/"></script>

or declaring a snooze on a script

<script defer src="https://js.arcgis.com/3.14/"></script>

However, this does not solve the root of the problem, because basically the component will not use AMD, but rather a global browser to declare it

Do you have any ideas? I have included jsFiddle for this:

https://jsfiddle.net/h9ztsrm3/5

Just turn on the console window and you may see a problem with several problems, thanks!

jsFiddle, arcgis dojo AMD, AMD, , , ,

https://jsfiddle.net/w33zwjhx/


:

1) - arcgis, asp.net mvc 5 bootstrap 3

2) asp.net mvc 5 script

<script src="/Scripts/jquery-2.1.4.js"></script>
<script src="/Scripts/bootstrap.js"></script>

3)

<script src="/Scripts/esri/3.14/init.js"></script>

4) 3 dojo, arcgis dojo

5) , , .

https://github.com/ehpc/bootstrap-waitingfor/blob/master/src/waitingfor.js

<script src="/Scripts/ehpc/waitingdialog/src/js/waitingdialog.js"></script>

6) , dojo arcgis, "if"

if (typeof define === 'function' && define.amd) {
    define(['jquery'], function ($) {
        return (root.waitingDialog = factory($));
    });
}

7) jsFiddle

8) , , - , define (['jquery']) -

http://ifandelse.com/its-not-hard-making-your-library-support-amd-and-commonjs/

+4
2

, , , , HTML .

jQuery AMD, AMD. jQuery, , jQuery :

<script src="https://js.arcgis.com/3.14/"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
<script>
    require([ 'jquery' ], function ($) { ... });
</script>

( jQuery $ .)

jQuery AMD :

<script>
    var dojoConfig = {
        async: true,
        paths: {
            jquery: 'https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min'
        }
    };
</script>
<script src="https://js.arcgis.com/3.14/"></script>
<script>
    require([ 'jquery' ], function ($) { ... });
</script>
+1

, . :

1), define (['jquery'])

2), jquery arcgis dojo, dojo,

// jquery was loaded before AMD is available, now that AMD is made available after loading dojo,
// register jquery as an AMD module so that AMD compatible plugins are able to locate jquery
define('jquery', [], function () { return jQuery; });

3) dojoConfig arcgis dojo

var dojoConfig = {
  packages: [{
    name: 'newmodule',
    location: '/Scripts/newmodule',
    main: 'newmodulejs'
  }]
};

4)

require(['newmodule', 'dojo/domReady!'], function (newModule) {
    // newModule.myfunc();
});

,

+1

Source: https://habr.com/ru/post/1616855/


All Articles