PDA

View Full Version : Trying to Pull Store Data into List Item Listener



markwyner
16 Mar 2011, 12:34 PM
Hello,

I have a data store which I'm referencing in an Ext.List. I am applying a tap listener to the list items but can't seem to get the data referenced from the store in the listener function. I'm pretty sure the issue is in one line where I'm referencing the data value I need (var name = record.data.itemName).

My store looks like this:


Ext.regModel('Items', {
fields: ['itemName']
});

AppName.StoreItems = new Ext.data.Store({
model: 'Items',
sorters: 'itemName',
getGroupString : function(record) {
return record.get('itemName')[0];
},
data: [
{itemName: 'AAA Item 1'},
{itemName: 'BBB Item 5'},
{itemName: 'CCC Item 1'},
{itemName: 'DDD Item 6'},
]
});

The list looks like this:


new Ext.List({
store: AppName.StoreItems,
itemTpl: '{itemName}',
grouped: true,
listeners: {
tap: {
element: 'el',
fn: function(record) {
var name = record.data.itemName;
AppName.ItemsDetails.dockedItems.items[0].setTitle(name);
AppName.ItemsDetails.update(record.data);
AppName.ItemsWrapper.setActiveItem('items_details', {type:'slide', direction:'left'});
}
}
}
})

When I tap a list item I get the following error in the console:


Uncaught TypeError: Cannot read property 'itemName' of undefined

So it clearly can't find the data in the listener function. I know everything else is set up properly, though, because I can log a note in the console using this:


fn: function() { console.log('hello'); }

So I must simply be missing part of the variable string to pull the data.

Any help would be greatly appreciated. Thanks in advance!

markwyner
16 Mar 2011, 2:37 PM
I had to come to my own rescue. So for those who find this post while searching for a solution to a comparable problem, I wanted to post the working solution:


listeners: {
itemtap: function(list, index) {
var name = list.store.getAt(index);
AppName.ItemsDetails.dockedItems.items[0].setTitle(name.data.itemName);
AppName.ItemsDetails.update(name.data);
AppName.ItemsWrapper.setActiveItem('items_details', {type:'slide', direction:'left'});
}
}

Ismailp
18 Jul 2011, 5:31 AM
Hey Mark,
Was wondering if you could point me in the right direction.

I want to populate a textfield with an item selected from a list. Can't seem to get it to work.

Could you help me out on this?'

Best regards,
Ismailp