Select to view content in your preferred language

Trying to use the Dojo/domReady! function

4099
4
Jump to solution
04-24-2013 09:03 AM
JimLongwill
Occasional Contributor
Hello,

This is in regards to using the modern Dojo/domReady! function for initializing a script & map.

I was using the code:   dojo.addOnLoad(init);   to load the page and map; however, when replacing that with the newer:

require(["dojo/domReady!"], function(init){});   it does not appear to work.

I also tried variations including:   require(["dojo/domReady!"]);   ... and putting it in different places in the code; but to no avail.

Do you have some examples on how to use this new Dojo syntax?   Any suggestions on how to use it?  I can provide the code if desired.

Many thanks!
0 Kudos
1 Solution

Accepted Solutions
JimLongwill
Occasional Contributor
I'm just starting out on all this, and I haven't figured out the syntax on the 'require' and context, etc.

Thanks for the example.

View solution in original post

0 Kudos
4 Replies
ReneRubalcava
Honored Contributor
dojo/domReady! only waits for the dom to load before returning. This is fine in most situations, but if you have dijits and other items that need to be loaded, it doesn't care if your dependencies are ready. If that is an issue, try using dojo/ready to wait for other dependencies to load.

dojo/domReady
http://dojotoolkit.org/reference-guide/1.8/dojo/domReady.html

dojo/ready
http://dojotoolkit.org/reference-guide/1.8/dojo/ready.html

So with a brief, but clear explanation
http://stackoverflow.com/a/13144258
0 Kudos
JimLongwill
Occasional Contributor

Thanks odoe,

I will use dojo/Ready as that *is* working at this point.  I've been seeking as much as possible to make my code V1.8 compliant; however, I can see that it will take some more experimenting to get Domo/domReady! to work.   I am loading other modules including..
      dojo.require("dijit.dijit"); // optimize: load dijit layer 
      dojo.require("dijit.layout.BorderContainer");
      dojo.require("dijit.layout.ContentPane");
      dojo.require("esri.map");
      dojo.require("dijit.layout.TabContainer"); 
      dojo.require("esri.dijit.Legend");
.
0 Kudos
derekswingley1
Deactivated User
What are you expecting to happen with this code:
require(["dojo/domReady!"], function(init){});


That will not behave the same say way as:
dojo.addOnLoad(init);


If you want to execute a function named init after the DOM is ready, use:
require(["dojo/domReady!"], init);


Here's a working example that creates a map:  http://jsfiddle.net/RyVE3/
0 Kudos
JimLongwill
Occasional Contributor
I'm just starting out on all this, and I haven't figured out the syntax on the 'require' and context, etc.

Thanks for the example.
0 Kudos