PDA

View Full Version : form.load local json object



topcoder1
22 Aug 2007, 1:39 PM
I want to know how to load a local json object into the form, see my code below. it returns


root has no properties
readRecords(Object success=false errorMessage=invalid command)ext-all-debug.js (line 11110)
read(Object tId=2 status=200 statusText=OK)ext-all-debug.js (line 11049)
handleResponse(Object tId=2 status=200 statusText=OK)ext-all-debug.js (line 24360)
processResponse(Object tId=2 status=200 statusText=OK)ext-all-debug.js (line 24223)
success(Object tId=2 status=200 statusText=OK)ext-all-debug.js (line 24347)
apply(function(), Object form=Object options=Object reader=Object, [Object tId=2 status=200 statusText=OK, Object scope=Object timeout=30000 method=POST], undefined)ext-yui-adapter.j... (line 10)
handleResponse(Object tId=2 status=200 statusText=OK)ext-all-debug.js (line 5034)
setProgId(Object conn=XMLHttpRequest tId=2, Object scope=Object argument=Object timeout=30000, undefined)yui-utilities.js (line 16)
setProgId()




loadForm:function(){



this.form.load({'rows':[
{'nlw_name':'myname'
,'nlw_des': 'mydes'
}
]
});



},
initForm:function(){
var RecordDef = Ext.data.Record.create([
{name: 'nlw_name', mapping: 'nlw_name'}, // "mapping" property not needed if it's the same as "name"
{name: 'nlw_des'} // This field will use "occupation" as the mapping.
]);
var myReader = new Ext.data.JsonReader({
//totalProperty: "results", // The property which contains the total dataset size (optional)
root: "rows" // The property which contains an Array of row objects
// id: "id" // The property within each row object that provides an ID for the record (optional)
}, RecordDef);
this.form=new Ext.form.Form({
url: 'action_nlwform.php'
,baseParams:{'cmd':'edit_nlw'}
,reader:myReader
});
var nameField=new Ext.form.TextField({
fieldLabel: 'NLW Name',
name: 'nlw_name',
id: 'nlw_name',
width:150,
allowBlank:false
});
var desField=new Ext.form.TextField({
fieldLabel: 'Description',
name: 'nlw_des',
id: 'nlw_des',
width:150

});

devnull
22 Aug 2007, 4:54 PM
I believe form.load() wants an an object containing key/value pairs; an associative array basically.


this.form.load(
{'nlw_name':'myname'
,'nlw_des': 'mydes'
}
});

topcoder1
22 Aug 2007, 7:00 PM
form.load is not intended for loading field values from local json objects, right?
it can only load data remotely it seems...

devnull
23 Aug 2007, 8:36 AM
Doh! yes you are right, you want loadData for a local data record, OR form.setValues for a local object (like i described above). if you use the latter you can get rid of the reader, if the latter then i think you will need a datastore of some sort.