PDA

View Full Version : loading data from json works but when accessing in the view the store object empty



pkvenu
22 Nov 2011, 4:32 PM
Hi guys,

I am having some issue with sencha touch data store. I am loading the data from jsonp to a store. The data is getting stored correctly. but when i access the view immediately with the store value and the object is empty.

I am not sure why?

data store :


parking.stores.ParkingFacility = new Ext.data.Store({
model: 'PF',
autoLoad: true
});

var GetData = function (lat, long) {
Ext.util.JSONP.request({
url: 'http://stg-parking.511.org/index/M_GetParkingFacilitiesByLatLng',
callbackKey: 'callback',
params: { latitude: lat, longitude: long },
callback: function (data) {
var result = data.Root;
parking.stores.ParkingFacility.loadData(data.Root);
parking.stores.ParkingFacility.save();
}

});


};

The GetData function populates the store with the json value.

View:


parking.views.mapComponent = Ext.extend(Ext.Panel, {
title: 'Map',
mapOptions: {
center: new google.maps.LatLng(37.381592, -122.135672),
zoom: 12,
mapTypeId: google.maps.MapTypeId.ROADMAP,
navigationControl: true,
navigationControlOptions: {
style: google.maps.NavigationControlStyle.DEFAULT
}
},
listeners: {
render: function (comp, map) {

var pdata = parking.stores.ParkingFacility;

}
}

});

The pdata value in the listener is empty. if i code breaks i see the pdata with values.

Any help would be greatly appreciated.

Regards,
Pawan

mitchellsimoens
23 Nov 2011, 11:21 AM
Have you done the loadData when the render happens? If not, then you need to wait for the store to have data before you can do that.