PDA

View Full Version : Very Simple Store with Json Reader



claytantor
26 Nov 2010, 2:39 PM
Yes it is true I am very new to Sencha, and Ext but I am really confused why this returns a record count of 0, when the app loads it seems to parse the JSON just fine, but somehow there are no records. Its bizarre because I have twiddled with this for many hours and this is the "by the book" as I can tell. Looked on forums already too I promise.


/**
* simple json store
*/
Ext.regApplication({
name: "json",
icon: 'resources/images/icon.png',
glossOnIcon: false,
phoneStartupScreen: 'resources/images/phone_startup.png',
tabletStartupScreen: 'resources/images/tablet_startup.png',

/**
* This is called automatically when the page loads.
*/
launch: function() {
// create the Data Store
var authInfosStore = new Ext.data.Store({
storeId: 'authInfosStore',
proxy: {
type: 'ajax',
url: 'http://dev.ratecred.com/oauth/url.json',
reader: {
type: 'json',
idProperty: 'authenticationURL',
root: 'urls',
totalProperty: 'count'
}
},
fields: [
{name: 'authenticationURL'},
],
});
authInfosStore.load();
console.log("loaded:"+authInfosStore.getCount());
}
});


{
"count" : 1,
"urls" : [{"authenticationURL": "https://auth.com/oauth/authenticate?oauth_token=PE0XNed8nMCphIk2oOmLjphUtWJmHvLzFvRWRHriUc"}]
}

claytantor
26 Nov 2010, 2:46 PM
This is resolved with the following callback approach. Found in the cool "Similar Threads" section.


authInfosStore.load(
{
callback:function(){
console.log("loaded:"+authInfosStore.getCount());
}
}
);

edspencer
26 Nov 2010, 6:20 PM
Looks like you solved it yourself :) This happens because all data loading is asynchronous which means you need to pass in callback functions that are called once the data has come back from your server.