PDA

View Full Version : Problem loading data store



JA12
15 Nov 2011, 6:48 AM
I'm trying to load a data store:


messages = Ext.regModel('Messages', { fields: [
{name: 'id', type: 'int'},
{name: 'orientation', type: 'int'},
{name: 'message', type: 'string'},
],
proxy: {
type: 'localstorage',
id: 'id'
},
});


messagesList = new Ext.data.Store({
model : 'Messages', // regModel name
data : [
{"id": "0", "orientation": "3", "message": "No Value passed to panel"},
{"id": "1", "orientation": "0", "message": "This one should be orientation 0"},
{"id": "2", "orientation": "1", "message": "This one should be orientation 1"},
{"id": "3", "orientation": "2", "message": "This one should be orientation 2"},
{"id": "4", "orientation": "3", "message": "O3: This is some text to display in the popup And a bit more to see what happens"}
]
});


//add listener to store's load event before you execute store.load():
messagesList.on({
'load':{
fn: function(store, records, options){
//store is loaded, now you can work with it's records, etc.
console.info('store load, arguments:', arguments);
console.info('Store count = ', messagesList.getCount());
},
scope:this
},
'loadexception':{
//consult the API for the proxy used for the actual arguments
fn: function(obj, options, response, e){
console.info('store loadexception, arguments:', arguments);
console.info('error = ', e);
},
scope:this
}
});


messagesList.load();

at this point messagesList.getCount() is always 0.

Even if I use autoload, the count is always 0.

I first tried using a json load from a .json file, but that doesn't work either



messagesListe = Ext.create('Ext.data.Store', { model: 'Messages',
proxy: {
type: 'ajax',
url : '/messages.json',
reader: {
type: 'json'
}
}
});
with the messages.json file:

{ "messages": [
{"id": "0", "orientation": "3", "message": "No Value passed to panel"},
{"id": "1", "orientation": "0", "message": "This one should be orientation 0"},
{"id": "2", "orientation": "1", "message": "This one should be orientation 1"},
{"id": "3", "orientation": "2", "message": "This one should be orientation 2"},
{"id": "4", "orientation": "3", "message": "O3: This is some text to display in the popup And a bit more to see what happens"},
]
}
How can I get the data load to work?

mankz
15 Nov 2011, 10:59 AM
Using a reader is a good idea :). All you're missing is the 'root' config since your data is wrapped in a 'messages' property.



messagesListe = Ext.create('Ext.data.Store', { model: 'Messages',
proxy: {
type: 'ajax',
url : '/messages.json',
reader: {
type: 'json',
root : 'messages'
}
}
});

JA12
16 Nov 2011, 1:02 AM
Thanks for that, but the

console.log(messagesList.getCount());
still returns 0 for either method...

Is there a delay on the load (I wouldn't have thought so for just 4 tiny records) so that the event fires too soon?