PDA

View Full Version : how to use loadRecord()



henrymuro
9 Jan 2012, 5:42 PM
I am struggling with the proper use of loadRecord to populate a Form Panel in Sench Touch 1.1. I have searched the forums and still can not figure this out. I stripped down my form to the bare minimum trying to get it to work and now I am stuck. Any help is appreciated. Here is my stripped down code

Ext.setup({

onReady: function() {

var projectModel = Ext.regModel('projModel', {
fields: [
{name: 'project_id', type: 'string'},
{name: 'project_name', type: 'string'}
]
});

var projectStore = new Ext.data.JsonStore({
model : 'projModel',
storeId: 'projStore',
autoLoad: true,
fields: [
{name: 'project_id', type: 'string'},
{name: 'project_name', type: 'string'}
],
proxy: {
type: 'ajax',
url: 'project.json',

reader: {
type: 'json'
}
}


});

var projectForm = new Ext.form.FormPanel({
fullscreen: true,
id: 'projForm',
dockedItems:[
{
xtype: 'toolbar',
dock: 'top',
title: 'Project 1',
}
],
items: [
{
xtype: 'textfield',
label: 'Project ID',
name: 'project_id'
},
{
xtype: 'textfield',
label: 'Project Name',
name: 'project_name'
},
]
});

var record = projectStore.getAt(0);
projectForm.loadRecord(record);
}
});

project.json returns the following

[{"project_id": "1211", "project_name": "My test Project"}]

Both the fields in the store and form match but the form is still not getting populated with the data

AndreaCammarata
10 Jan 2012, 2:19 AM
The first thing you have to check is if you are store is populated.
What do you see if you write what follows?



console.log(projectStore.getCount());


I'm pretty sure your problem is that you are trying to fill your form when the store still didn't read the records. Remember that the store read operation is async.
Try to fill the form by pressing, for instance, a button and not at application load.

Hope this helps.

PS: Please wrap your Code inside Code tags.