PDA

View Full Version : Fill form with JSON data



prodigy7
17 Aug 2009, 11:02 PM
Hi there,

I've the following situation:

I've a form ... this form has 2 fields with the name 'forename' and 'surname'
I've JSON data which contains {"forename":"test1", "surname": "test2"}

How I can assign the content (JSON data) to the form after the form is created and drawn... somehow it can be done, loading json data and assign it - but how I can do that with an variable which contains already data?

prodigy7

BitPoet
17 Aug 2009, 11:05 PM
Use the underlying BasicForm's 'getValues (http://extjs.com/deploy/ext-3.0.0/docs/?class=Ext.form.BasicForm&member=setValues)' method to do just that.
I.e. yourform.getForm().setValues({"forename": "test1",...});

prodigy7
17 Aug 2009, 11:41 PM
Ah okay ... would mean, that I parse somehow the keys/values and set then the values.

BitPoet
17 Aug 2009, 11:44 PM
If you have the raw string, use something along


var vals = Ext.decode(jsonstring);
yourform.getForm().setValues(vals);

prodigy7
18 Aug 2009, 5:00 AM
Thank you very much - solves my problem!