在我的 dojo 应用程序中,我正在尝试动态加载模块,该模块在我构建代码之前可以正常工作。一旦使用dojo构建系统构建代码,相同的模块就会以整数(特别是3)而不是模块本身的形式加载。
下面是正在运行的代码,即在构建应用程序之前
var loadModule = "MyModule.js";
var path = "./js/path/to/MyModule/";
require([path+loadModule], lang.hitch(this,function (myModule) {
//do something with myModule
//this works without any problem
}))
现在通过 dojo 构建系统的同一段代码变成如下所示并且不起作用
var _23 = "MyModule.js";
var _24 = "./js/path/to/MyModule/";
require([_24 + _23], _2.hitch(this, function(_25) {
//here this '_25' is number 3 instead of myModule. which i wonder why!
}))
对于 dojo 构建系统,我使用以下配置
layerOptimize: "shrinksafe",
optimize: "shrinksafe",
cssOptimize: "comments",
mini: true,
stripConsole: "warn",
selectorEngine: "lite",
编辑:在我的应用程序中,我试图动态加载的模块负责处理 openlayers 地图。该模块的基本代码如下
define(["dojo/_base/declare", "dojo/_base/lang", "dojo/_base/window", "dojo/dom", "dojo/dom-construct", "dojo/topic","dojo/dom-style","dojo/on",
"dijit/registry","dijit/Tooltip","dijit/TooltipDialog","dijit/popup","dijit/ConfirmDialog",
"dojox/collections/Dictionary"
],
function(declare, lang, baseWindow, dom, domConstruct, topic, domStyle, on,
registry,Tooltip,TooltipDialog,dijitPopup,ConfirmDialog,
Dictionary){
var olMapModule = {};
olMapModule.initMap = function(){
//Code for openlayer go here
};
olMapModule.initMapInteractions = function(){
//code for initiating the map interactions go here
};
return olMapModule;
});
Edit2:逗号被错误地放置了。此外,在完成 dojo 构建之前,这段代码确实可以完美运行。