Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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 dijit.layout.ContentPane({id:'abccp',title:'abc', href:abchref});

How can I call do_abc() in the programmatic ex

like image 777
noru Avatar asked Jan 07 '11 15:01

noru


1 Answers

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
like image 54
Ken Franqueiro Avatar answered Oct 22 '22 11:10

Ken Franqueiro