在我的代码中使用ArcGIS API for JavaScript v4.4时,我遇到了这个奇怪的问题。我正在尝试构建一个Excel Web外接程序,我想在其中加载一个ArcGIS地图,但当我加载ArcGIS时,我得到了一个multipleDefine错误。
ArcGIS与Dojo捆绑在一起,它被用作所有ArcGIS/esri包的加载器。由于ArcGIS构建其应用程序接口的方式,我没有其他选择来使用Dojo加载我自己的自定义JS包。因此,我不能决定不使用Dojo,因此不能得到multipleDefine
错误。
我像这样加载我自己的JS文件:
<script src="https://appsforoffice.microsoft.com/lib/1/hosted/office.js" type="text/javascript"></script>
<script>
var dojoConfig = {
parseOnLoad: false,
async: false,
// we make aliases for our js file
aliases: [
['index', './Bundles/index.js'],
],
};
</script>
<script src="https://js.arcgis.com/4.4/init.js"></script>
<script>
require(['index'], function (index) {
//...do something
});
</script>
当我重新启动页面时,每2/3次试验中就会出现一次multipleDefine
错误。经过大量调查,我知道错误出在Office.js应用程序接口上,但我很难找到一个好的解决方案。
发布于 2017-10-30 12:56:12
过了一段时间,我找到了问题的原因;我们不能一起启动multipleDefined -js和Dojo,因为它们都想在页面的head标签中添加脚本,但不知何故它们彼此冲突,因此我们得到了可怕的office-js Dojo错误,并且我们的一些文件无法加载。
一旦确定了原因,我决定通过确保在Office和依赖项完全加载后加载Dojo、Argis和我的自定义js文件来解决它。
我在我的js代码中是这样实现的:
// This Dojo config variable has to be defined before Dojo is loaded in our scripts
var dojoConfig = {
// we make aliases for our custom js file
aliases: [
['index', './Bundles/index.js'],
],
// We require our dependencies (our own code bundles) with Dojo.
// Notice that it is mandatory to bundle our js files
// as AMD Modules for Dojo to be able to load them as dependencies.
deps: ['index'],
};
// Once office has fully initialized we can add our arcgis file and let
// him load our own required javascript files.
// We cannot start Office-js and Dojo/Arcgis together because they both
// want to add scripts in the head tag of the HTML page and
// somehow they end up in conflict, thus we get the dreaded
// multipleDefined Dojo error and some of our files
// do not get loaded.
Office.initialize = function (reason) {
// we manually add the Arcgis script to the header of our page
// once we are sure Office and dependencies has fully loaded.
var tag = document.createElement('script');
tag.src = 'https://js.arcgis.com/4.4/init.js';
document.getElementsByTagName('head')[0].appendChild(tag);
};
一旦添加了这一点,代码就开始像护身符一样工作。
https://stackoverflow.com/questions/47015850
复制相似问题