小智 15
startup()在_Widget中定义,并且只是"生命周期的一部分".这是小部件生命周期的最后一步,并非所有小部件都需要.绝对需要的最常见情况是以编程方式创建布局小部件.当孩子需要调整大小时,它被用作防止冗余计算的方法.例如,BorderContainer.
var bc = new dijit.layout.BorderContainer({
style:"height:200px; width:200px"
});
// can call bc.startup() now, and the BorderContainer will resize
// all children each time a new child is added. Or, we can add all
// our children now, then trigger startup() and do it all at once.
var top = new dijit.layout.ContentPane({
region:"top", style:"height:100px"
}).placeAt(bc);
var mid = new dijit.layout.ContentPane({ region:"center" }).placeAt(bc);
// now BC will do the calculations, rather than in between each
// the above addChild/placeAt calls.
bc.startup();
Run Code Online (Sandbox Code Playgroud)
在parseOnLoad:true或手动执行的情况下,解析器会自动调用Startup.解析器延迟调用startup()直到所有找到的子窗口小部件都被适当地实例化.
dijit.Dialog是一个奇怪的案例.必须在这个小部件上调用startup().
var dialog = new dijit.Dialog({ title:"Hmm", href:"foo.html" });
dialog.startup();
dialog.show();
Run Code Online (Sandbox Code Playgroud)
大多数小部件不需要启动调用,但是在从_Widget继承的东西不覆盖启动成员的情况下,调用本质上是一个无操作设置this._started = true; 如果您创建自己的startup()函数,则应该调用this.inherited(arguments)或者只需手动设置_started触发器.
在Dojo 1.4中,这里的生命周期略有调整.以前,具有widgetsInTemplate:true的窗口小部件将在父窗口上的启动()之前调用子窗口小部件上的startup().在1.4中,子启动()将在父启动()之后调用.此行为是递归的,但是实例化了具有widgetsInTemplate:true的许多级别的嵌套窗口小部件.
调用.startup()始终是"安全的",但如果您"知道"(因为它是一个简单的端点小部件,或您自己的自定义_Widget代码),您可以省略该调用.
归档时间: |
|
查看次数: |
12843 次 |
最近记录: |