PDA

View Full Version : Store with JsonReader



chieroz
1 Sep 2009, 6:14 AM
Hi.

I have a problem with the code below: protocolliRead.php is sending data, but Firebug says "reader is undefined". I read the documentation, but I cannot find where my problem is...

If I plug off the reader, change the store in JsonStore and move the configuration items in the store, everything works fine. (NB I put here only the relevant code)

Thank you for your help.


var protocolliProxy = new Ext.data.HttpProxy({
api: {
read: '/php/protocolliRead.php',
create: '/php/protocolliCreate.php',
update: '/php/protocolliUpdate.php',
destroy: '/php/protocolliDelete.php'
}
});

var recordFieldsProtocolli = [{
name: 'id',
mapping: 'id',
type: 'int'
}, {
name: 'protocollo',
mapping: 'protocollo'
}];

var protocolliReader = new Ext.data.JsonReader({
idProperty: 'id',
totalProperty: 'results',
successProperty: 'success',
root: 'rows',
fields: recordFieldsProtocolli
});

var protocolliWriter = new Ext.data.JsonWriter({
writeAllFields: false,
encode: true
});

var storeProtocolli = new Ext.data.Store({
storeId: 'storeProtocolli',
autoLoad: false,
remoteSort: true,
autoSave: false,
reader: protocolliReader,
writer: protocolliWriter,
proxy: protocolliProxy,
listeners: {
exception: function(){
console.info(arguments);
}
}
});

BlueCamel
1 Sep 2009, 12:32 PM
I looked at this but didn't see where it might be failing. Can you supply the json response that worked when you used an Ext.data.JsonStore?

Jack9
1 Sep 2009, 12:49 PM
The API lists a reader and an updater in the proxy. Too bad you already specified a reader/writer before specifying the proxy.

reader: protocolliReader,
writer: protocolliWriter,
proxy: protocolliProxy,


Even I'm confused as to what the store is supposed to use. You probably dont want a separate reader/writer since you're attempting to use a proxy (which does everything)

chieroz
1 Sep 2009, 10:24 PM
I get the same JSON response in both cases.

chieroz
1 Sep 2009, 10:26 PM
I used the code in the writer.js code (http://extjs.com/deploy/dev/examples/writer/writer.js). That's why I cannot figure out what's wrong...