PDA

View Full Version : FormPanel with JsonReader



jpsequeira
29 Jun 2008, 12:06 PM
I've searched and searched ...

This is my code:


var Client = Ext.data.Record.create([
{name: 'nomeprincipal', mapping: 'np'},
{name: 'outroscontactos', mapping: 'oc'},
{name: 'elem001', mapping: 'bi'},
{name: 'elem002', mapping: 'al'},
{name: 'elem003', mapping: 'nf'},
{name: 'elem004', mapping: 'an'},
{name: 'elem005', mapping: 'ou'},
{name: 'obs', mapping: 'ob'}
])

var clientReader = new Ext.data.JsonReader({root: "data"}, Client);

var x1 = new Ext.FormPanel({
id: count_tabs,
labelWidth: 125, // label settings here cascade unless overridden
frame:true,
layout: 'form',
renderTo: 'form',
reader:clientReader,
closable: true,
autoWidth : true,
title: 'Interveniente '+key,
bodyStyle:'padding:5px 5px 0',
items: [{
xtype:'tabpanel',
activeTab: 0,
defaults:{autoHeight:true, bodyStyle:'padding:10px'},
items:[{
title:'Dados',
layout:'form',
defaults: {width: 280},
defaultType: 'textfield',
items: [
{
fieldLabel: 'Nome Principal',
name: 'np',
id: 'np',
allowBlank:false
},{
fieldLabel: 'Outros Contactos',
name: 'oc'
},{
fieldLabel: 'B.I.',
name: 'bi'
}, {
fieldLabel: 'Altura (cm)',
name: 'al'
}, {
fieldLabel: 'N.F.C.',
name: 'nf'
},{
fieldLabel: 'Ano Nasc.',
name: 'an'
},{
fieldLabel: 'Outro',
name: 'ou'
},{
fieldLabel: 'Observ.',
name: 'ob',
type: 'textArea'
}
]
}, grid]
}]
});

My Json returns this:


{"success":true,"data":[{"id":"500","nomeprincipal":"Nuno Ricardo Cobra Rosa Santos","outroscontactos":"","obs":"Agente da tv cabo em Elvas","elem001":"","elem002":"","elem003":"","elem004":"","elem005":""}]}

Where do I specify the URL where to load the data from?
I've tried in a lot of diferent places. Nothing seems to work.

Am I doing this right at all ???
I mean .. the clientReader and all ??? Is there a better way to load the JSON data into the form ???

Please help. Thank you.

Animal
29 Jun 2008, 11:12 PM
Dno't use a JsonReader, it just add complexity. A Form understands JSON anyway.