开发者

using onShow and onLoad for dijit.layout.ContentPane created programatic

I have a ContentPane created both declarative and programmatic.

Declarative :

<div dojoType="dijit.layout.ContentPane" id="abccp" href="abc.php?id=1" title="abc" onShow="do_abc()">

Programmatic

var obj_abc;
var abchref= "abc.php?id=1";
obj_abc = new 开发者_如何学JAVAdijit.layout.ContentPane({id:'abccp',title:'abc', href:abchref});

How can I call do_abc() in the programmatic ex


To be technically equivalent to your first example, you'd just include onShow: do_abc within the arguments object passed to ContentPane's constructor. (Note no parentheses after do_abc - we're interested in the function object itself, not the result of calling it!)

However, if you'd like to do it in a bit more extensible of a fashion, then I'd suggest doing it like this:

obj_abc = new dijit.layout.ContentPane(...);
obj_abc.connect(obj_abc, 'onShow', do_abc);

What this does is perform a hookup such that whenever obj_abc's onShow method is called, the do_abc function will in turn be called (though in the context of obj_abc, which presumably is what you want anyway). You also get the following added bonuses:

  • It no longer clobbers any default functionality that might be originally present in the method (though in this case, onShow is a stub meant to be clobber-able)
  • You can connect any number of functions to onShow in this way
  • The connection will automatically be torn down when the widget is destroyed (as opposed to dojo.connect which you would have to tear down manually).

For more information:

  • http://dojotoolkit.org/api/dijit/_Widget/connect
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜