简体   繁体   English

如何在Dojo AMD中包括旧模块

[英]How to include legacy module in Dojo AMD

I'm trying to migrate an application from dojo 1.6 to version 1.9.1, and I've a legacy module that I didn't want to migrate yet (it's pretty complex and will take me some time to understand). 我正在尝试将应用程序从dojo 1.6迁移到版本1.9.1,并且我有一个我不想迁移的旧模块(它非常复杂,需要花费一些时间来理解)。 The Dojo docs indicate you can load legacy modules along with AMD modules, but when I try, I'm getting a "dojo.provide is not a function" when the loader tries to load the legacy module. Dojo文档指示您可以将旧模块与AMD模块一起加载,但是当我尝试时,加载器尝试加载旧模块时出现“ dojo.provide不是函数”的信息。

My script: 我的剧本:

require([..., "agsjs/dijit/TOC","dojo/domReady!"], 
            function(..., TOC) {
    on(map,'layers-add-result',function(results){
        //Add Legend
        var toc = new TOC({
            map: map,
            layerInfos:legendLayers
        }, 'legendDiv');
        toc.startup();
    });
});

The first line of code of the module: 模块的第一行代码:

dojo.provide('agsjs.dijit.TOC');

Everything works until the loader tries to load the agsjs/dijit/TOC module, where I get a "dojo.provide is not a function" error. 一切正常,直到加载器尝试加载agsjs / dijit / TOC模块为止,在该模块中出现“ dojo.provide不是函数”错误。 How do I solve this without having to refactor the entire module to AMD? 我如何解决此问题而不必将整个模块重构为AMD? Thanks 谢谢

In order for legacy modules to load, you need to run the loader in legacy mode, which means you cannot set async: true . 为了加载旧版模块,您需要在旧版模式下运行加载程序,这意味着您无法设置async: true As long as you are running with async: false (the default), you will be able to load and use legacy modules from AMD modules, and vice-versa. 只要您使用async: false (默认设置)运行,您就可以从AMD模块中加载和使用旧模块,反之亦然。

A good point of AMD is that you don't have to use "dojo" and "dijit" global variables now. AMD的一个优点是您现在不必使用“ dojo”和“ dijit”全局变量。 If you don't want change all those dojo.xxx calls in your old modules, you may try to wrap you old module in a 如果您不想更改旧模块中的所有dojo.xxx调用,则可以尝试将旧模块包装在

define([
    "dojo/_base/declare", 
    "dojo", "dijit", 
        ...  
], function(declare, dojo, dijit) {

   return declare([/*your parent widgets*/], {

   //your old module content at here, maybe  you need make little modifications of your old module

   });

});  

So that those dojo.xxx functions may still works. 这样那些dojo.xxx函数仍然可以工作。

This link may provide everything you need: 该链接可能提供您需要的一切:

http://dojotoolkit.org/reference-guide/1.9/releasenotes/migration-17.html http://dojotoolkit.org/reference-guide/1.9/releasenotes/migration-17.html

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM