View Full Version : accessing JsonStore data

4 Aug 2010, 6:29 PM
Hello All,

I have a JsonStore set up which I need to access some data from. I've been able to bind it to a List successfully and render the list just fine. I'm also able to handle itemtap events successfully and switch between items based on the parameters that are passed to the itemtap handler.

But I need to access some of the data in the JsonStore to complete the initialization of the view I'm working on. I've tried to do this in a similar manner to the way I access the data when I'm doing the itemtap event handling but it just doesn't seem happy with this, I keep getting undefined objects and the like. So I'm thinking there must be another way to handle what I'm trying to do? Thoughts? Below is an example of my setup to give you an idea.

this.headlinesList = new Ext.List({
baseCls: 'headlinesListCls',
id: 'headlinesListId',
scroll: false,
store: this.headlinesJStore,
tpl: Ext.XTemplate.from('headlines'),
itemSelector: 'div.headlines',
singleSelect: true,
listeners: {
itemtap: function(thisView, index ) {
var selectedHeadlineId = thisView.store.getAt(index).data.id;
var newsPanel = Ext.getCmp('newsPanel');


var id = this.headlinesList.store.getAt(0).data.id;

To point out specific lines, the first bolded blue line in the itemtap handler works just fine. But when I try to access the information in a similar manner, the second bolded blue line, I'm getting 'not an object' errors, or undefined (I've played with a bunch of little configurations of this).

I'm thinking that I'm approaching this in the wrong way so I figured I'd throw this out there for some help! Any is much appreciated. :D

4 Aug 2010, 6:35 PM
You didn't show the store definition, but I'm guessing you're loading from a remote data source? If so, chances are the store isn't loaded by that point.

4 Aug 2010, 6:51 PM
Hi Evan, Thanks for all the replies, I definitely appreciate them while I'm getting up to speed with all this.

It is a remote data source. If I insert a
console.log(this.headlinesList.store); right before the line
var id = this.headlinesList.store.getAt(0).data.id;, then in the safari web inspector I'm able to open up the object and find the data that I'm trying to access. I thought that this was an indication that the store was ready at this point. Is that not a good way to check that?

4 Aug 2010, 7:19 PM
No, not a good way. Since you're logging the store, you're logging a reference. By the time you actually click into the console to view it, the data has already loaded.

console.log(store, store.getCount());

Count will be 0, but when you go and inspect it, data will be filled.