Dojo定时问题与dijit / registry和dojo / domReady [英] Dojo timing issue with dijit/registry and dojo/domReady
问题描述
当通过脚本标签包含以下代码时,它记录未定义:
require([dijit / registry,'dojo / domReady!'],function(registry){console.log(registry.byId('my- ID')) });
当我将它粘贴到控制台中时,我得到了预期的dijit小部件。
我怀疑问题是这是在页面呈现之前触发的。有一个简单的方法来确保在当前文档被完全解析并包含在主窗口中之后发生这种情况?
在尝试访问窗口小部件之前,可以尝试添加 Parser
并调用 Parser.parse()
。
这是来自Dojo文档
请注意,等待
dojo / domReady!
在窗口小部件工作时通常不足以支付
。许多小部件不应该被初始化或
访问,直到以下模块加载和执行:
- dojo / uacss
- dijit / hccss
- dojo / parser
I am working on a one-page application in Dojo which submits forms via ajax and returns parses the return value before rendering the page. When I go about this I end up with a timing error.
When the following code is included via a script tag, it logs undefined:
require(["dijit/registry", 'dojo/domReady!'], function(registry){ console.log(registry.byId('my-id')) });
When I paste it in the console, I get the expected dijit widget.
I suspect that the problem is that this is firing before the page is rendered. Is there an easy way to ensure that this happens after the current document has been fully parsed and included in the main window?
May be you should try, to add Parser
and call the Parser.parse()
before trying to access the widget.
This is from Dojo documentation
Note that waiting for
dojo/domReady!
to fire is often not sufficient when working with widgets. Many widgets shouldn’t be initialized or accessed until the following modules load and execute:
- dojo/uacss
- dijit/hccss
- dojo/parser
这篇关于Dojo定时问题与dijit / registry和dojo / domReady的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!