PDA

View Full Version : getting row fields vals from JsonStore



valititi
8 Jan 2011, 11:15 AM
Hy. I have a list... Ok list... Now for editing records, when I cal from this list


myStoreList.getAt(rowIndex)).get('pays_iden')
all goes fine. I got my needed id and then load a editing window, where I have a similar JsonStore :



var retIden=0; var retNume='';

function setVals(st) {
st.each(function(v){
retIden=parseInt(v.get('pays_iden'));
retNume=(v.get('pays_nume')).toString();
alert(retNume); // <--- this alert goes fine, here, and return 'France'
});
}
var mypu=new Ext.data.ScriptTagProxy({url:'qGetRow.php'});
var stRow=new Ext.data.JsonStore({
storeId:'rowStore', url:mypu, successProperty:'success', autoDestroy:true, stateful:false,root:'arrVals',
fields:[
{name:'pays_iden' , type:'int'}, {name:'pays_nume'}
],
listeners:{
load: setVals,
loadexception: function(){Ext.Msg.show({title:'Err',msg:'LoadErr',modal:true,icon:Ext.Msg.INFO,buttons:Ext.Msg.OK});return} }
});
stRow.load();
alert('ext'+retNume); // <--- this alert not return the correct data
I read that is asynchronous, and returns immediately... Buw HOW can I get this value ? I need the vals for then filling my form and be able to do an update. The returned json is :

{"success":"true","arrVals":[{"pays_iden":"3","pays_nume":"Spain"}]}Thanks for you answer.

Condor
8 Jan 2011, 12:07 PM
Loading is asynchronous!

The load() method only sends a request to the server, but doesn't wait for the server to respond and continues with the next line of code.
When the server response is received the load callback method and the store load event handler are executed in which you can access the store data.

valititi
8 Jan 2011, 12:19 PM
thanks for answer Condor.
Is not in my setVals function ? there I have it the needed data. alert(reNume), in setVals are correclty "Spain".
But I need the data AFTER loads. to put fill my form with. On the list, when I call
myStoreList.getAt(rowIndex)).get('pays_iden')
I correclty got the id (3).
Here, if I call, after loads
stRow.getAt(rowIndex)).get('pays_iden')
this returns nothing ! Why ? Where and how may I call AFTER loads, to have my needed vals (id=3,nume="Spain") ?

valititi
8 Jan 2011, 8:47 PM
finally I load with a JsonReader in a FormPanel. and this solve some needs.