PDA

View Full Version : [OPEN] Label with tap event and onPainted



Igor Lapiga
12 Nov 2012, 10:17 AM
Hello,

I need label with tap event. I use this code in view:


items:[{
xtype: 'label',
listeners : {
single : true,
painted : function(component) {
//in ST 2.0
//component.element.on('tap', function(e, t) { component.fireEvent('tap', component, e, t); }, component);
//in ST 2.1
var element = component,
component = this;
element.on('tap', function(e, t) { component.fireEvent('tap', component, e, t); }, component);
}
}]

In ST 2.0 handler's parameter component = this = "my label".
Now, in ST 2.1 handler's parameter component is element("my label".element) and this = "my label".
Is this correct?
I think the documentation for Component painted event is incorrect.
http://docs.sencha.com/touch/2-1/#!/api/Ext.Component-event-painted

mitchellsimoens
12 Nov 2012, 3:04 PM
That is true and I will open a bug however there is a better way to do what you are wanting to do:


Ext.Viewport.add({
items : [
{
xtype : 'label',
html : 'I am a label',
listeners : {
element : 'element',
tap : function(e, t) {
this.fireEvent('tap', this, e, t);
}
}
}
]
});

Igor Lapiga
13 Nov 2012, 2:56 AM
This is perfect! Thank you!