PDA

View Full Version : Load Data to Form (JSON)



kastolia
24 Mar 2014, 7:54 AM
Hello everybody! I need your help!

I have a FormPanel in extjs 3.4 and I want to load data from seerver via a webservlet but I am a bit confused. :(

The webservlet responses with the following JSON information:
{"items":{"address":"1","email":"a@a.gr","lastname":"aaa","firstname":"olia"},"success":true}

I tried two ways:
A. After layout.setActiveItem('FormPanellID'); I
I used:
FormPanel .getForm().load({ url: 'servletURL',
failure: function(form, action) {
Ext.Msg.alert("Load failed", action.result.errorMessage);
}
});
but I get the failed message!

B. I create a new Ext.data.JsonStore
var panelStore = new Ext.data.JsonStore({ autoLoad: true,
autoDestroy: true, url : 'servletURL',
root: 'items',
fields: [' 'email', 'firstname', 'address', 'status', 'lastname', ''],
listeners : {
load: function(store, records, options){
if(records[0]){
FormPanel.getForm().loadRecord(records[0]);
} else{
console.log("no data!");
}
}
}
});

and then I call panelStore .load();
but nothing happens!

I try 5 days to load data to a form but nothing! I thought that extjs was not too difficult :(
Could you please help me?

chramer
24 Mar 2014, 10:05 AM
'root' property should be applied to reader, not to store..
Check the example from the docs: http://docs.sencha.com/extjs/4.2.2/#!/api/Ext.data.JsonStore