dijit.byId not ready at body onload? When are dijits actually available?
-
06-07-2019 - |
Question
I'm using Dojo toolkit version 1.3.1. I have defined the following dijit in a jsp page:
<div dojoType="dijit.layout.BorderContainer" gutters="false" id="ui_container">
<div dojoType="dijit.Toolbar" region="top">
<div dojoType="dijit.form.Button" id="zoomin" iconClass="zoominIcon">Zoom In</div>
</div>
<div dojoType="dijit.layout.BorderContainer" gutters="false" region="center">
<div dojoType="dijit.layout.ContentPane" id="mapPane" region="center"><div>hi</div>
</div>
</div>
</div>
In the onload event for my body tag I specify a function with this code in it:
var container_id = "ui_container";
// blah blah blah some stuff in the middle here
dijit.byId(container_id).resize({h: new_container_height});
And I get this error when viewing the page: dijit.byId(container_id) is undefined.
It works if I add a check to exit the function and call it again in 100 ms when this value is undefined, but that's a sloppy hack. Is there some more precise way to know when dijits are available for use?
Solution
It doesn't really mention this very clearly in the docs I read, but it looks like dojo.addOnLoad was what I was looking for.
Thanks!
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow