View Full Version : assigning normal links to Ext

16 Aug 2007, 11:46 PM
As i'm still a beginner in ExtJS and not quite good in JS i need a hint how to do it with iterations.

I have a div with some links inside and on click i want to open a Dialog like LayoutExample from Demo.
Atm i generate a handler for each link that seems to be not a good way:

foreach($ids as $f){
$s.= "var showBtn".$f['uid']." = Ext.get('ulink_".$f['uid']."');
// attach to click event
showBtn".$f['uid'].".on('click', this.showDialog, this);";

1) Is there a way to iterate all a-tags of this div and assign a clickhandler?
2) how can i determine inside showDialog which link was clicked?

would be nice if someone could enlighten me ;)


16 Aug 2007, 11:55 PM
You'd probably want to use DomQuery to do it, for example, you could give all those links a class:

<a href="#" class="linkType">Link 1</a>
<a href="#" class="linkType">Link 2</a>
<a href="#" class="linkType">Link 3</a>

Ext.select('a.linkType').on('click', function(e)
var el = Ext.get(e.getTarget()); //el is now an Ext.Element that raised the event.

More info here: http://extjs.com/deploy/ext/docs/output/Ext.DomQuery.html

17 Aug 2007, 12:02 AM
Hi evant,

wow, quick response, thx :)
Ok, that seems to be a good way to do.

Leaves part 2 of my question - i have an id in the links (or may be i put it to another place) as unique identifier.
In my example i call the Object showDialog also with "this", but inside the object i didn't found a way to reference to "this". How can i do, is there an object like "parent" or "caller" ?

17 Aug 2007, 2:09 AM
'this' refers to the current scope. I suggest you read up a bit, http://extjs.com/forum/showthread.php?t=6336 is good.