PDA

View Full Version : Tap event on list won't fire



Eraesr
23 Apr 2012, 4:48 AM
Hi,

I've got the following view defined:



Ext.define('TSW.view.sdp_popup', {
extend: 'Ext.Panel',


config: {
id: 'sdp_popup',
cls: 'bs_body',
centered: true,
modal: true,
height: Ext.Viewport.getWindowHeight() * 0.75,
width: Ext.Viewport.getWindowHeight() * 0.6,
hideOnMaskTap: true,
items: [
{
id: 'filteritems',
xtype: 'list',
cls: 'bs_body',
height: (Ext.Viewport.getWindowHeight() * 0.75) - 15,
itemTpl: '<div class="mn_row_content_table"><strong>{NAME}</strong></div>',
onItemTap: function() {
console.log('something');
}
}
]
},


bindStore: function(store) {
if (typeof(store) == 'string')
store = Ext.getStore(store);


var c = Ext.getCmp('filteritems');
c.setStore(store);
}
});


it's a floating panel component that contains a list. The list is displayed and populated properly. It has a custom bindStore function because I need to be able to pass different stores to it to display. I didn't want to create the same view 5 times for 5 different stores.

The problem I face is that the list doesn't respond to me tapping items (the "console.log('something');" line isn't executed). I tried to pass a listeners config object instead of defining the onItemTap as well but it didn't work either. Elsewhere in my application, I also have a list that's defined as its own view, meaning that the way it's defined is not through an "items" config option but similar to how the Panel is defined in the above example. That list does respond to the onItemTap event.

Does anyone know why the above doesn't work?

Eraesr
23 Apr 2012, 5:32 AM
Oh, found the answer in this thread (http://www.sencha.com/forum/showthread.php?176239-HOWTO-Adding-Event-Listeners-to-Component-Elements).

I changed the view by replacing



onItemTap: function() {
console.log('something');
}


with



listeners: {
itemtap: {
fn: function() { console.log('something'); },
element: 'element'
}
}


See the itemtap event (http://docs.sencha.com/touch/2-0/#!/api/Ext.dataview.List-event-itemtap) on Ext.List for info on arguments that are passed into the event handler.