I've created a custom proxy type for retrieving data from a javascript remoting method that returns an array of objects. The issue is that during autoLoad, the ListStore shows values in the "Contacts" array. However, once I click on a List component bound to this store, the Contacts array for each record is cleared. I suspect is has something to do with
Code:
read: function (operation, callback, scope) { //Here goes your read logic
HTML5RemoteExtensions.query('Select ID,Name,Type,AccountNumber,Industry,AnnualRevenue,Phone, (Select Id, Name from Contacts) from Account',function handleResponse (result, event) { //, (Select Id, Name from Contacts)
console.log(JSON.stringify(result));
demos.ListStore.loadData(result.records);
demos.ListStore.sort('Name', 'ASC');
demos.ListStore.loading = false;
demos.ListStore.sync();
}, {escape:false}
);
},
And the Model:
Code:
Ext.regModel('Account', { fields: ['Id', 'Name', 'Type', 'AccountNumber', 'Industry', 'AnnualRevenue', 'Phone', 'Contacts'],
associations:[
{type: 'hasMany', model: 'Contact', name: 'Contacts'}
],
idProperty: 'Id',
proxy: {
type: 'myProxy',
reader: {
type: 'json',
totalProperty: 'totalSize',
successProperty: 'done',
root: 'records'
}
}
});
Ext.regModel('Contact', {
fields: ['Id', 'Name', 'AccountId'],
belongsTo: ['Account', {model: 'Account', associationKey: 'AccountId'}],
idProperty:'Id'
});
And the data returned from initial "read":
Code:
{"records":[{"Name":"test5","RecordTypeId":"012U0000000KLkCIAW","Type":"first","Id":"001U00000071eXtIAI","Industry":"first"},{"Name":"GenePoint","Phone":"(650) 867-3450","AccountNumber":"CC978213","Type":"second","Contacts":[{"Name":"Edna Frank","AccountId":"001U0000002KPCDIA4","Id":"003U0000001XpgCIAS"}],"Id":"001U0000002KPCDIA4","AnnualRevenue":30000000,"Industry":"Biotechnology"}]}
And the debug of the ListStore after rendering the list component:
Code:
{"Name":"GenePoint","Phone":"(650) 867-3450","AccountNumber":"CC978213","Type":"second","Contacts":[],"Id":"001U0000002KPCDIA4","AnnualRevenue":30000000,"Industry":"Biotechnology"}