PDA

View Full Version : Populate a form from store in ExtJS 4



Prasath Moorthy
4 Oct 2012, 3:22 AM
I have used the following code to load data from my store to a form in ExtJs, but i am not able to retrieve the data to my textfield.

Ext.onReady(function() {
var formPanel = Ext.create('Ext.form.Panel', {
title: 'Form Panel',
width: 350,
height: 200,

style: 'margin: 50px',
renderTo: 'musicianProfile', // the name of the div in my JSP
reader: new Ext.data.JsonReader({
type: 'json',
root: 'data',
fields: [
{name: 'firstName', type: 'string'},
{name: 'lastName', type: 'string'}
]
}),
items: [{
xtype: 'container',
layout: 'hbox',
items: [{
fieldLabel: 'First Name',
xtype: 'textfield',
name: 'firstName',
readOnly: true,
flex: 1,
}, {
fieldLabel: 'Last Name',
xtype: 'textfield',
name: 'lastName',
readOnly: true,
flex: 1,
}]
}]
});
formPanel.getForm().load({
method:'GET',
url:'ajax/viewMusicianMembers.htm' //URL that produces a JSON result
});
});

The value that i receive to my browser is:

{
"success":true,"total":1,"message":null,
"data":[{"firstName":"System","lastName":"Administrator"}],
"errors":null
}

Can anyone help me to find out where the mistake is, and how to rectify it?

redraid
4 Oct 2012, 3:43 AM
Read http://docs.sencha.com/ext-js/4-0/#!/api/Ext.form.action.Load