are there better ways to call Js API modules in a Jquery Widget?

846
6
06-20-2017 01:34 PM
HemingZhu
Occasional Contributor III

I am currently upgrade a jquery ui widget to use Js API 4.x. I was using Js API 3.x in my widget, since the 3.x support legacy code, i could call a module or class easily; for example, this.locationGraphic=new esri.Graphic(center, symbol, feature.attributes, infotemplate). The 4.x no longer support legacy code, l have to load those AMD module into the widget, which is not simple. I could pass those class or module parameters into my widget to avoid loading. But it is a long list. Is there any better ideas or simple ways to do it?(Any ideas are welcome:))

0 Kudos
6 Replies
RobertScheitlin__GISP
MVP Emeritus

Heming,

l have to load those AMD module into the widget, which is not simple

What is not simple about that? Just like you have your requires in your main js code you just define the modules in your custom widget code.

0 Kudos
HemingZhu
Occasional Contributor III

Robert,

I don't know if there are better way to load, which is why i am asking this question. I don't need to load those module in 3.x. when i create a graphic, i could just call in my widget code

var graphic=new esri.Graphic(....); now i have to pass the parameter like the following

require(["esri/Graphic",...], function(Grapic){

   ....

    view.then(function () {
      //load the portal tool kit
      $('#tool').location_portal({
            view: view,
            movable: true,

            Graphic: Graphic   
         });
   });

   ........

});

Maybe i did it wrong way, just ask here to see if there are better or correct ways to do it

 

RobertScheitlin__GISP
MVP Emeritus

Heming,

   No there is not a simpler or better way that is the AMD module way of doing things. You were able to by pas this in the past because of Legacy coding style but now in 4.x Legacy is not supported so you are required to load all modules using AMD style coding.

HemingZhu
Occasional Contributor III

I know 4.x is AMD only. So i am aware of that. Just don't want my jquery widget have too many dependencies, maybe i will bypass, using Jquery.trigger() to pass JSON object and let hosting page to deal with JSON uing API. Thanks for answering my question. It is indeed helpful.

0 Kudos
ThomasSolow
Occasional Contributor III

You'll have fewer dependence this way, since you'll only be loading only the modules you need.

I imagine using the older style, you're loading everything, even if you're only using a small number of classes.

0 Kudos
HemingZhu
Occasional Contributor III

when working with 3.x, i don't need to load any modules, because the hosting page already include the API link, i only need to use legacy code when i created instance of a class. now, i have to pass module to my widget. that is what i mean. Thanks for response anyway.

0 Kudos