listeners on DataView in Sencha Touch 2
-
27-10-2019 - |
Question
I got a problem with a Dataview
. The Dataview
should have a listeners on the items it renders.
so here is how my Dataview
looks like:
var childrenData = Ext.create('Ext.DataView', {
store: {
fields: ['id', 'name', 'children'],
proxy: {
type: 'ajax',
url: '/category/view',
reader: {
type: 'json',
}
},
autoLoad: true,
},
itemTpl: childrenTemplate,
listeners: {
itemtap: function(data,index){
var record = data.getStore().getAt(index);
console.log(record);
}
}
});
Has anybody, any Idea why this doesn't work?
Edit: added Template data: var childrenTemplate = new Ext.XTemplate('', '', '', '{name}', '', '', '', ' {price}', '', '', '', '' );
Solution 2
I found out what the Problem was.
The dataview was in a Container that was in a TabPanel.
After some trial and error, I found out that if I define the Container as an configuration object with xtype: 'container' it works. If I create the Container over Ext.create('Ext.Container', {}); it somehow doesn't work. Already asked in Sencha Forum if its a Bug or a Feature, I'll keep you updated.
OTHER TIPS
Please try below code; (for sencha-touch-2)
var childrenData = Ext.create('Ext.DataView', {
store: {
fields: ['id', 'name', 'children'],
proxy: {
type: 'ajax',
url: '/category/view',
reader: {
type: 'json',
}
},
autoLoad: true,
},
itemTpl: childrenTemplate
});
add listener with;
childrenData.on({
tap: function(data,index){
var record = data.getStore().getAt(index);
console.log(record);
}
});