如何在Dojo AMD中包含遗留模块 [英] How to include legacy module in Dojo AMD

查看:120
本文介绍了如何在Dojo AMD中包含遗留模块的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将应用程序从dojo 1.6迁移到1.9.1版本,而且我还有一个我不想迁移的遗留模块(这很复杂,需要一些时间才能理解)。 Dojo文档表明您可以加载旧模块以及AMD模块,但是当我尝试时,当加载程序尝试加载旧模块时,我会得到一个dojo.provide不是一个功能。

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). 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.

我的脚本:

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();
    });
});

模块的第一行代码:

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

一切正常,直到加载程序尝试加载agsjs / dijit / TOC模块,在那里我得到一个 dojo.provide不是函数错误。如何解决这个问题,而不必将整个模块重构为AMD?谢谢

Everything works until the loader tries to load the agsjs/dijit/TOC module, where I get a "dojo.provide is not a function" error. How do I solve this without having to refactor the entire module to AMD? Thanks

推荐答案

为了使旧版模块加载,您需要以旧模式运行加载程序,这意味着您无法设置 async:true 。只要您使用 async:false (默认值)运行,您将能够加载和使用AMD模块的旧模块,反之亦然。

In order for legacy modules to load, you need to run the loader in legacy mode, which means you cannot set 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.

这篇关于如何在Dojo AMD中包含遗留模块的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆