Я полагаю, что что-то подобное может работать, хотя я не проверял это:
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-виджетов выполняется через точки расширения, вызываемые в следующем порядке:
- postMixinProperties
- buildRendering
- postCreate <==. Теперь ваш виджет был превращен в HTML и вставлен в страницу, и вы можете получить доступ к таким свойствам, как this.domNode. Тем не менее, ни один из дочерних виджетов не позаботился о </li>
- запуск: это последняя вызванная точка расширения, после отрисовки всех дочерних виджетов
(Это объяснение жизненного цикла виджетов в «Мастеринг додзё»).
ПРИМЕР:
<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>