PDA

View Full Version : JSON from static file



vitalyny
4 Nov 2008, 12:47 PM
Hi,

I'm trying to re-do sample script. In ext2.2/samples.js there is:



var catalog = [{
title: 'Combination Samples',
samples: [{
text: 'Feed Viewer 2.0',
url: 'feed-viewer/view.html',
icon: 'feeds.gif',
desc: 'RSS 2.0 feed reader sample application that features a swappable reader panel layout.'
}]
}];


I tried to save that as a separate file Test.json. Added root element and id. So it looks like this:



{ data: [{
id: 1,
text: 'Feed Viewer 2.0',
url: 'feed-viewer/view.html',
icon: 'feeds.gif',
desc: 'RSS 2.0 feed reader sample application that features a swappable reader panel layout.'
},{
id: 2,
text: 'Simple Tasks 2.0',
url: 'http://extjs.com/blog/2008/02/24/tasks2/',
icon: 'air.gif',
desc: 'Complete personal task management application sample that runs on <a href="http://labs.adobe.com/technologies/air/" target="_blank">Adobe AIR</a>.'
}] }


And now I try to load .json file instead of having all this json code in .js file:



var galleriesList = new Ext.data.Store({
url:'Data/Test.json',
reader: new Ext.data.JsonReader({
root: 'data',
id: 'id'
}, ['id', 'text', 'url', 'icon', 'desc'])
});
var catalog = [{
title: '2008',
galleries: galleriesList
}];
var store = new Ext.data.JsonStore({
idProperty: 'id',
fields: ['id', 'title', 'galleries'],
data: catalog
});
new Ext.Panel({
autoHeight: true,
collapsible: true,
frame: true,
title: 'All My Galleries',
items: new GalleryPanel({
store: store
})
}).render('all-galleries');


But it doesn't show up. What am I doing wrong?

devnull
4 Nov 2008, 2:31 PM
I dont see where youve told it to load the store at any point.
do you see it being loaded in the firebug console?

vitalyny
4 Nov 2008, 6:35 PM
Line: url:'Data/Test.json',
Is that incorrect? I was also trying to use proxy:

var galleriesList = new Ext.data.Store({
proxy: new Ext.data.HttpProxy({
url: 'Data/Test.json',
method: 'GET'
}),
reader: new Ext.data.JsonReader({
root: 'data',
id: 'id'
}, ['id', 'text', 'url', 'icon', 'desc'])
});

but that didn't work too.

watrboy00
4 Nov 2008, 7:13 PM
How are you running this? On a local IIS/Apache server? I know in my experience with IIS you have to map the .json extension first before it can be used.

vitalyny
5 Nov 2008, 6:51 AM
IIS 7, but I know about this issue. I did all required steps and verified with treeview sample, which uses .json file. It's working fine.