PDA

View Full Version : question about form and load function with json



noog
2 Nov 2010, 6:27 AM
hello
i try to load some data on a form
i read this page of the doc

http://dev.extjs.com/deploy/dev/docs/?class=Ext.form.Action.Loadthis is my code :

MyViewport = Ext.extend(MyViewportUi, {
initComponent: function() {
MyViewport.superclass.initComponent.call(this);
var sm = this.grid.getSelectionModel();
sm.on('rowselect',this.onGridRowSelect,this);
},
onGridRowSelect: function (sm,rowIdx,r){
// Ext.getCmp('workspace').update(r.data);
Ext.getCmp('workspace').load({
url: 'test.php',
params: {
id:1
}
});
console.log('Row was clicked'+rowIdx);
//Ext.Msg.alert("OK"+rowIdx);
}
});in test.php i have inserted a echo of my json file
this is the json in the php file

{
"data": [
{"id":"1","title": "test1","field1":"564654","field2": "97789"},
{"id":"2","title": "test2","field1" : "54564","field2" : "2451"}
]
}and this is the configuration of my form


items: [
{
xtype: 'form',
title: 'workspace',
id:'workspace',
autoScroll: true,
items: [
{
xtype: 'fieldset',
title: 'Project',
items: [
{
xtype: 'textfield',
fieldLabel: 'title',
anchor: '80%',
id: 'title'
},
{
xtype: 'textfield',
fieldLabel: 'field1',
anchor: '80%',
id: 'field1'
},
{
xtype: 'textfield',
fieldLabel: 'field2',
anchor: '80%',
id: 'field2'
}
]
},
but the informations are not populated
thks

Screamy
2 Nov 2010, 11:51 AM
It looks like you forgot to include the name attribute of the fields in your form panel. I refactored the fieldset below to show how each form field should look:


{
xtype: 'fieldset',
title: 'Project',
items: [{
xtype: 'textfield',
fieldLabel: 'title',
anchor: '80%',
id: 'title',
name: 'title'
},{
xtype: 'textfield',
fieldLabel: 'field1',
anchor: '80%',
id: 'field1'
name: 'field1'
},{
xtype: 'textfield',
fieldLabel: 'field2',
anchor: '80%',
id: 'field2'
name: 'field2'
}]
}

Condor
3 Nov 2010, 4:38 AM
A form can't load multiple records. Your server should be returning:

{
"success": true,
"data": {"id":"1","title": "test1","field1":"564654","field2": "97789"}
}