PDA

View Full Version : Json Data Store



shurrock
16 Jun 2011, 12:14 PM
Hey guys,

I am currently trying to populate a list with a json file, ive copied the format and the code exactly from tutorials found, and demos on this site, but im still getting nothing.

If someone could help me it would be awesome!

Thanks!

my json file:




{"patients":[
{"id":"1", "firstName":"Category 1", "lastName":"lastname"},
{"id":"2", "firstName":"Category 2", "lastName":"lastname"},
{"id":"3", "firstName":"Category 3", "lastName":"lastname"},
{"id":"4", "firstName":"Category 4", "lastName":"lastname"},
{"id":"5", "firstName":"Category 5", "lastName":"lastname"},
{"id":"6", "firstName":"Category 6", "lastName":"lastname"}
]}



My datastore code



Ext.regModel('Contact', {
fields: ['id','firstName', 'lastName']
});


ListDemo.OnlineStore = new Ext.data.JsonStore({
model: 'Contact',
proxy: {
type: 'ajax',
url: 'javascript/patients.json',
reader: {
type: 'json',
root: 'patients'
}
}
});



ListDemo.listPanel = new Ext.List({
id: 'disclosurelist',
store: ListDemo.OnlineStore,
itemTpl: '<div class="contact">{firstName} {lastName}</div>',
grouped: true,
onItemDisclosure: false,

listeners: {
itemtap: onSelect
}
});



any help would be awesome!

Thanks!

Tom:-?

bclinton
16 Jun 2011, 3:54 PM
I don't know if this is what is causing the problem, but you have grouped set to true in your list but you don't have any groupField defined in your store.

shurrock
16 Jun 2011, 10:13 PM
Hey,

Thanks for your reply.

I have removed the grouped part of the list now, so the items will no be grouped (just to test) and i am still not getting anything.

Here is my code now



ListDemo.OnlineStore = new Ext.data.JsonStore({
model: 'Contact',
proxy: {
type: 'ajax',
url: 'javascript/patients.json',
reader: {
type: 'json',
root: 'patients'
}
}
});

ListDemo.listPanel = new Ext.List({
id: 'disclosurelist',
store: ListDemo.OnlineStore,
itemTpl: '<div class="contact">{firstName} {lastName}</div>',
onItemDisclosure: false,

listeners: {
itemtap: onSelect
}
});




Really weird, as chrome isnt spitting out any errors to be at all, so im completely unsure what the problem is.:-/

Thanks again

steve1964
17 Jun 2011, 3:50 AM
You have to load your store:


ListDemo.OnlineStore = new Ext.data.JsonStore({
model: 'Contact',
autoLoad : true,
proxy: {
type: 'ajax',
url: 'javascript/patients.json',
reader: {
type: 'json',
root: 'patients'
}
}
});

shurrock
17 Jun 2011, 4:11 AM
omg! its working, you hero! thankyou so much.

Im still quite new to this, so annoyed that i just missed the obvious mistake!

Thanks again mate!:D