PDA

View Full Version : [solved] Is MemoryProxy and JsonReader it possible?



Thylia
31 Aug 2007, 2:20 AM
This code goes if I use the HttpProxy but not if I use MemoryProxy



var reader = new Ext.data.JsonReader({
root:'LstChamps',
totalProperty:'NbChamp',
id:'CodCha'
},Ext.data.Record.create([
{name:'LabCha', mapping:'LabCha' },
{name:'CodCha', mapping:'CodCha' },
{name:'widthcolumn', mapping:'widthcolumn'},
{name:'labelWidth', mapping:'labelWidth' },
{name:'widthfield', mapping:'widthfield' },
{name:'Fmt', mapping:'Fmt' },
{name:'Lenght', mapping:'Lenght' },
{name:'Option', mapping:'Option' },
{name:'FctTst', mapping:'FctTst' },
{name:'TabTst', mapping:'TabTst' },
{name:'TabGuide', mapping:'TabGuide' },
{name:'CodGuide', mapping:'CodGuide' },
{name:'Ong', mapping:'Ong' },
{name:'DatGuide', mapping:'DatGuide' }
]));
this.SaiGriStore = new Ext.data.Store({
// proxy: new Ext.data.HttpProxy({url:'SaiChamps.js'}),
proxy: new Ext.data.MemoryProxy(Exemple.responseArray),
reader: reader
});
this.SaiGriStore.load();

this.SaiGriStore.on('load', function() {
alert('ok');
});

Animal
31 Aug 2007, 2:23 AM
What does Exemple.responseArray look like?

Thylia
31 Aug 2007, 2:32 AM
Exemple.responseArray = Ext.util.JSON.decode(response.responseText);


response.responseText :


// SaiEmp.js
({
"NbOnglet":2,
"LstOnglet":[
{"CodOng":"Ong1","LibOng":"Options simples"},
{"CodOng":"Ong2","LibOng":"Options avancees"}
],
"NbChamp":11,
"LstChamps":[
{"LabCha":"RefElt" ,"CodCha":"RefElt" ,"widthcolumn":230,"labelWidth":60,"widthfield":60 ,"Fmt":"t","Lenght":"8" ,"Option":"r","Ong":"Ong1" },
{"LabCha":"CodEmp" ,"CodCha":"CodEmp" ,"widthcolumn":230,"labelWidth":60,"widthfield":60 ,"Fmt":"t","Lenght":"6" ,"Option":"o","Ong":"Ong1","FctTst":TestExist ,"TabTst":"PcaEmp" },
{"LabCha":"Nom" ,"CodCha":"Nom" ,"widthcolumn":230,"labelWidth":60,"widthfield":150,"Fmt":"t","Lenght":"20","Option":"o","Ong":"Ong1" },
{"LabCha":"Prenom" ,"CodCha":"Prenom" ,"widthcolumn":270,"labelWidth":60,"widthfield":150,"Fmt":"t","Lenght":"20","Option":"" ,"Ong":"Ong1" },
{"LabCha":"Matricule","CodCha":"Matricule" ,"widthcolumn":230,"labelWidth":60,"widthfield":150,"Fmt":"n","Lenght":"8" ,"Option":"" ,"Ong":"Ong1","FctTst":TestNoExist,"TabTst":"PcaPerso" },
{"LabCha":"CodAcc" ,"CodCha":"CodAcc" ,"widthcolumn":150,"labelWidth":60,"widthfield":50 ,"Fmt":"c","Lenght":"10","Option":"" ,"Ong":"Ong1" ,"TabGuide":"PcaAcc","CodGuide":"CodAcc"},
{"LabCha":"CCA" ,"CodCha":"CCA" ,"widthcolumn":100,"labelWidth":60,"widthfield":1 ,"Fmt":"b","Lenght":"1" ,"Option":"" ,"Ong":"Ong1" },
{"LabCha":"BNS" ,"CodCha":"BNS" ,"widthcolumn":230,"labelWidth":60,"widthfield":1 ,"Fmt":"b","Lenght":"1" ,"Option":"" ,"Ong":"Ong1" },
{"LabCha":"Regul" ,"CodCha":"Regul" ,"widthcolumn":150,"labelWidth":60,"widthfield":50 ,"Fmt":"b","Lenght":"1" ,"Option":"" ,"Ong":"Ong2" },
{"LabCha":"Act" ,"CodCha":"Act" ,"widthcolumn":150,"labelWidth":60,"widthfield":50 ,"Fmt":"c","Lenght":"1" ,"Option":"o","Ong":"Ong1" ,"TabGuide":"PolAct","CodGuide":"Act" },
{"LabCha":"TypDti" ,"CodCha":"Type de demande","widthcolumn":150,"labelWidth":60,"widthfield":50 ,"Fmt":"c","Lenght":"1" ,"Option":"o","Ong":"Ong1" ,"CodGuide":"TypDti","DatGuide":['I','E','S','M']}
]})

Animal
31 Aug 2007, 3:05 AM
Should work. You'll have to debug it in Firebug. Step into the load method and follow it through.

Use ext-all-debug.js

Thylia
31 Aug 2007, 5:31 AM
The problem came owing to the fact that the SaiGriStore.load() was made before the SaiGriStore.on('load', ...
This problem did not exist with the HttpProxy

Animal
31 Aug 2007, 5:52 AM
That's just user error. an HttpProxy is a bit slower to return the data of course, and so the next statement, which added the listener executed before the data returned and the load event fired.