PDA

View Full Version : Controller listening for click on <a> tag.



xjscrafter
22 Jul 2014, 12:03 PM
I want to create a custom component that has several <a> tags in a div.

I want an ExtJS controller to listen for the click events, and respond based on what <a> tag link was clicked.

Sample code below. Any ideas would be welcome.


Ext.onReady(function() {
Ext.create('Ext.container.Viewport', {
renderTo: Ext.getBody(),
layout: 'fit',
items: [{
xtype: 'container',
layout: {
type: 'hbox',
align: 'middle'
},
items: [{
xtype: 'component',
html: '<div>' +
'<ul>' +
'<li><a class="one">One</a></li>' +
'<li><a class="two">Two</a></li>' +
'<li><a class="three">Three</a></li>' +
'</ul>' +
'</div>',
listeners: {
click: function(event) {
alert(event);
}
}
}]
}]
});
});

xjscrafter
22 Jul 2014, 1:47 PM
If I add an onclick to the tag, how would the controller know which tag was clicked?

israelroldan
24 Jul 2014, 4:39 AM
A managed listener may help: https://fiddle.sencha.com/#fiddle/819