This is just a little tip when trying to load local .json files using the Ext.data.Store ajax proxy type. The following code will work in Android 4.0.3+ but you need to be sure to add an extra couple lines to get it to work, noCache: false and enablePagingParams: false. Without those lines the code still works fine in Android 2.3.3 but for Android 4 and above, the ajax fails on loading local .json files because the requests url includes parameters added by Sencha.
Roads DataStore
Ext.define("Roads", {
extend:"Ext.data.Store",
requires:"Ext.data.proxy.LocalStorage",
config:{
fields: [
{ name: 'id', type: 'int' },
{ name: 'title', type: 'string' },
{ name: 'subtitle', type: 'string' }
],
proxy:{
type:'ajax',
url:'resources/data/roads.json',
reader:{
type:'json',
noCache: false,
enablePagingParams: false,
rootProperty:'roads'
}
},
listeners:{
load:function (s, r) {
console.log(r)
}
}
}
});
roads.json
{"roads":[
{
"id":"i10",
"title":"Interstate 10 Arizona",
"subtitle":"Papago Freeway/Maricopa Freeway"
},
{
"id":"i17",
"title":"Interstate 17 Arizona",
"subtitle":"Black Canyon Freeway"
},
{
"id":"l101",
"title":"Arizona State Route 101",
"subtitle":"Loop 101"
}
]}
References where the solution was found:
http://www.sencha.com/forum/showthread.php?190878-Android-local-json-store-not-loading
-Mister
‘resources/data/roads.json’
I still have a doubt about where to place the roads.json file. Should it exist under assets folder OR it can exist in android internal storage as in data/data//files.
In either case my sencha application is not able to access the json file. The error I get on log cat is “Unknown chromium error -6″.
Please help
You can put them in a res/raw folder, that is usually were you store xml documents and access it like a resource R.raw.roads