admin管理员组文章数量:1305843
i have recently started to work in dojo. dijit.byId() returns undefined even if i put this call inside dojo.onLoad().
<script type="text/javascript">
dojo.require("dijit.form.Select");
function myhandler(ev)
{
var mydiv = dojo.byId('mydivid');
if (ev == 'Disable') {
mydiv.style.display = 'none';
} else {
mydiv.style.display = 'block';
}
}
function regHandler()
{
var item = dijit.byId("myState");
alert(item);//shows undefined
dojo.connect(dijit.byId("myState"), 'onChange', myhandler);
}
dojo.addOnLoad(regHandler);
</script>
<select input class="dialogInputElement" dojoAttachPoint="myState" dojoType=dijit.form.Select name="myState" id="myState" value='Enable' style="margin-bottom:5px">
<option value="Enable">Enable</option>
<option value="Disable">Disable</option>
</select>
it works fine if i delay dijit.byId() call with setTimeout(). dojo version is 1.4.2 Any solution or workaround will be appreciated.
Thanks in advance.
i have recently started to work in dojo. dijit.byId() returns undefined even if i put this call inside dojo.onLoad().
<script type="text/javascript">
dojo.require("dijit.form.Select");
function myhandler(ev)
{
var mydiv = dojo.byId('mydivid');
if (ev == 'Disable') {
mydiv.style.display = 'none';
} else {
mydiv.style.display = 'block';
}
}
function regHandler()
{
var item = dijit.byId("myState");
alert(item);//shows undefined
dojo.connect(dijit.byId("myState"), 'onChange', myhandler);
}
dojo.addOnLoad(regHandler);
</script>
<select input class="dialogInputElement" dojoAttachPoint="myState" dojoType=dijit.form.Select name="myState" id="myState" value='Enable' style="margin-bottom:5px">
<option value="Enable">Enable</option>
<option value="Disable">Disable</option>
</select>
it works fine if i delay dijit.byId() call with setTimeout(). dojo version is 1.4.2 Any solution or workaround will be appreciated.
Thanks in advance.
Share Improve this question edited Aug 24, 2011 at 17:46 user469635 asked Aug 24, 2011 at 17:36 user469635user469635 591 gold badge2 silver badges5 bronze badges 1-
I don't believe Dojo's onLoad event guarantees that dijits have been parsed and instantiated (and hence are available to
dijit.byId
). Do you haveparseOnLoad: true
in your dojoConfig? What happens if you adddojo.parser.parse();
to yourregHandler
(before the rest of its code)? – Frode Commented Aug 25, 2011 at 10:18
2 Answers
Reset to default 5If this is verbatim from your code, it looks like you are missing double-quotes from around your dojoType
declaration. If your input is never declared as a dijit widget, it will never be retrievable by dijit.byId()
.
If you want a more general node selector, use dojo.byId()
instead, it will select any node with an id, not just dijit widgets.
Have you tried adding the attribute djConfig="parseOnLoad: true" to the dojo configuration?
When you include the dojo.js library file you can set the attribute like this:
<script type="text/javascript" src="dojo/dojo.js"
djConfig="parseOnLoad: true">
</script>
In my tests, this seems to solve the problem. In this jsfiddle note if you remove the djconfig tag attribute (on the left nav bar) and run it, you get the behavior you are describing.
本文标签: javascriptdijitbyId() returns undefined even in dojoaddOnLoad()Stack Overflow
版权声明:本文标题:javascript - dijit.byId() returns undefined even in dojo.addOnLoad() - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741800652a2398201.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论