确定dijit的DOM是否已完成加载

时间:2010-03-09 19:38:13

标签: dom dojo

有没有办法查询dojo dijit来判断dijit的DOM是否已经完成加载?

2 个答案:

答案 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小部件的渲染是通过扩展点处理的,按顺序调用:

  1. postMixinProperties
  2. buildRendering
  3. postCreate< ==此时,您的窗口小部件已转换为HTML并插入到页面中,您可以访问此属性,例如this.domNode。但是,没有任何子窗口小部件被处理
  4. startup:这是在绘制完所有子窗口小部件后调用的最后一个扩展点
  5. (这是小部件'掌握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>