有没有办法查询dojo dijit来判断dijit的DOM是否已经完成加载?
答案 0 :(得分:3)
我相信如果设置了dijit的“domNode”属性,则会创建窗口小部件的DOM。小部件可以或可以不附加到较大的DOM,这可以是单独的步骤。将domNode.parentNode检查为真实元素可能会有所帮助,但不能保证parentNode也在实时文档中。
答案 1 :(得分:1)
我相信这样的事情可能有用,虽然我没有测试它:
if (yourWidget.domNode) {
// here your widget has been rendered, but not necessarily its child widgets
} else {
// here the domNode hasn't been defined yet, so the widget is not ready
}
Dijit小部件的渲染是通过扩展点处理的,按顺序调用:
(这是小部件'掌握Dojo'生命周期的解释)。
示例:
<html>
<head>
<script src="path/to/your/dojo/dojo.js" djConfig="parseOnLoad: true, isDebug: true"></script>
<script type="text/javascript">
dojo.require("dojo.parser");
dojo.require("dojox.lang.aspect");
dojo.require("dijit.form.Button");
// Define your aspects
var startupAspect = {
before : function() {console.debug("About to execute the startup extension point");},
after : function() {console.debug("Finished invoking the startup extension point");},
};
function traceWidget(theWidget) {
// Attach the aspect to the advised method
dojox.lang.aspect.advise(theWidget, "startup", startupAspect);
}
</script>
</head>
<body>
<button dojoType="dijit.form.Button" type=button">
dijitWidget
<script type="dojo/method" event="postCreate">
traceWidget(this);
</script>
<script type="dojo/method" event="startup">
console.debug("Inside startup");
</script>
</button>
</body>
</html>