PDA

View Full Version : Attach event to hyperlink(Ext.BoxComponent)



dranix
30 Nov 2011, 11:34 PM
Hi everybody
I have the problems which describe in the title. I have searched the forum and found this: http://www.sencha.com/forum/showthread.php?121647-How-to-attach-a-extjs-object-function-as-listener-to-hyper-link-button . However I can't do it. Maybe I'm missing something, would you please help me?

Here's my code:


var ExportBookItem = function () {
alert('clicked');
};


var exportHyperLink= new Ext.BoxComponent({
autoEl: {
id: 'exportHyperLink',
tag: 'a',
cn: 'Export'
}
});


exportHyperLink.mon(exportHyperLink, {
click: ExportBookItem,
buffer: 50
});



Thank in advance

mitchellsimoens
1 Dec 2011, 6:40 AM
Two things... you have to wait till the component is rendered to place a click listener on it because you need the el property of that component. The first argument you pass in mon() has to be an element:


var ExportBookItem = function () {
console.log('clicked');
};


var exportHyperLink= new Ext.BoxComponent({
renderTo : Ext.getBody(),
autoEl: {
id: 'exportHyperLink',
tag: 'a',
cn: 'Export'
},
listeners : {
afterrender : function(cmp) {
cmp.mon(cmp.el, {
click: ExportBookItem,
buffer: 50
});
}
}
});

That is working for me! Please notice that I added renderTo to the BoxComponent to make it render.

dranix
1 Dec 2011, 7:06 PM
Thank you so much.
I knew I missed something but I couldn't figure it out
Thank for your kind support