PDA

View Full Version : Help with ADDing a record



TampaBay55
6 Jan 2012, 10:57 AM
Greetings:

I have the following store:



Ext.define('LSIPay.store.UsrDataStore',{
extend: 'Ext.data.Store',
model: 'LSIPay.model.UsrData',
autoSync: true,
proxy: {
type: 'rest',
url: 'data/usrdata.php',
reader: {
type: 'json',
root: 'record',
successProperty: 'success'
},
writer:{
type: 'json'
}
},
listeners:{
'add': function(model,record,index,eobt){
console.log(record);
var view = Ext.widget('usrdataform');
view.down('form').loadRecord(record);
}
}
});


When I click the add button on my grid, the following code is executed:


addRecord: function(button){
var store = this.getUsrDataStoreStore();
var grid=button.up('usrdatabrowse');
var newRecord = Ext.create('LSIPay.model.UsrData');
store.add(newRecord);
},


The problem I am having is that the form does not load the record. I verified that the record has data in it. Can someone lend me some insight on what I am doing incorrectly?

mitchellsimoens
6 Jan 2012, 12:26 PM
The add listener sends an array of records that were added even if only one record was added. loadRecord only expects one record:


var form = Ext.create('Ext.form.Panel', {
renderTo : Ext.getBody(),
width : 400,
height : 400,
items : [
{
xtype : 'textfield',
name : 'test',
fieldLabel : 'Test'
}
]
});

var store = Ext.create('Ext.data.Store', {
fields : ['test'],
listeners : {
add : function(store, recs) {
form.loadRecord(recs[0]);
}
}
});

store.add({
test : 'Bam!'
});

TampaBay55
6 Jan 2012, 12:44 PM
Hi Mitchell:

Thank you for your response. I certainly appreciate any valuable information I can get while learning ExtJS. I modified the code as you stated and dug around to see exactly what it does. I still show the record object data containing the data I assigned in the PHP script; however the data is not populating the form. The difference between our methods is that I am priming data in the PHP script and not in Ext JS. Perhaps I need some kind of listener to fire the form load after the php script sends back the JSON record? Thanks again.

Shawn