PDA

View Full Version : how get data from a list when i tap 1 item



rolfiee
23 Aug 2011, 6:38 AM
I'm stuck on my list. I do not know how to recieve data from it. I have the following code:



Ext.regModel('Contact', {
fields: ['firstName', 'lastName']
});


var store = new Ext.data.JsonStore({
model : 'Contact',
sorters: 'lastName',


getGroupString : function(record) {
return record.get('lastName')[0];
},


data: [
{firstName: 'Tommy', lastName: 'Maintz'},
{firstName: 'Rob', lastName: 'Dougan'},
{firstName: 'Ed', lastName: 'Spencer'},
{firstName: 'Jamie', lastName: 'Avins'},
{firstName: 'Aaron', lastName: 'Conran'},
{firstName: 'Dave', lastName: 'Kaneda'},
{firstName: 'Michael', lastName: 'Mullany'},
{firstName: 'Abraham', lastName: 'Elias'},
{firstName: 'Jay', lastName: 'Robinson'}
]
});

var list = new Ext.List({
fullscreen: true,

itemTpl : '{firstName} {lastName}',
grouped : true,
store: store,
onItemTap: function(item) {
Ext.Msg.alert('Tap', 'Disclose more info for ' + item.get('firstname'), Ext.emptyFn);
}
});


But item.get('firstname') don't work.

jratcliff
23 Aug 2011, 7:19 AM
Remove your onItemTap code. That's an internal method that you shouldn't override. What you want to do is to 'listen' for the itemtap event and then have a handler function that runs when this event happens.



var list = new Ext.List({
fullscreen: true,
itemTpl : '{firstName} {lastName}',
grouped : true,
store: store,
listeners : {
itemtap : function(dataview, index, item, e) {
var store = dataview.getStore(),
rec = store.getAt(index);
Ext.Msg.alert('Tap', 'Disclose more info for ' + rec.get('firstName'));
}
}
});


Also, you had a typo with the 'firstName' field. It has a capital 'N' so don't forget that. :)

epiphanydigital
24 Aug 2011, 5:37 AM
Could also do something like:



itemtap : function(record,index){
var current = record.store.getAt(index);
Ext.Msg.alert('Tap that','Some info about ' + current.firstName);
}