kuprishuz
14 Jun 2007, 4:33 AM
When doing large applications, having to make multiple calls to the server to fill data stores (such as comboboxes, etc..) seems to drastically effect performance.
I have attempted to make one ajax call to the server and then use a MemoryProxy on each datastore to the returned result however i seem to be unsucessful as the datastore always seems to be empty, does anyone see a problem with the code below, or is there a better way of doing this.
Thanks in advance.
App.Customer= function(id, title) {
var mp = null;
var customerDs= null;
// retrieve data from the server
var load = function(){
Ext.Ajax.request({
url: 'borrower/data/id/'+id+'/',
callback: function(options, success, response){
if(success){
var data = Ext.decode(response.responseText);
mp = new Ext.data.MemoryProxy(data);
buildDataSources();
} else {
Ext.MessageBox.alert('Unknown Error', 'An unknown error occured while attempting to retreive the data, please contact a system administrator.');
}
},
scope: this
});
}
// build / load data stores.
var buildDataSources = function(){
// datastores
customerDs = new Ext.data.Store({proxy: mp,
reader: new Ext.data.JsonReader({root:'customers', id:'id'},
['id','company','leadsource','employee','title','firstname','middle','lastname',
'former','ssn','dob','permanent_street1','permanent_street2','permanent_city',
'permanent_state','permanent_zip','mailing_street1','mailing_street2','mailing_city',
'mailing_state','mailing_zip','primary_phone','secondary_phone','license_number',
'license_state','primary_email','secondary_email','createdate','fax','deleted',
'rtb','comments','active']),
remoteSort: false
});
customerDs.load();
}
load();
}
new App.Customer(15, "Firstname Lastname");
i believe this was a matter of callback scope, and execution order. either way i believe it to be funcitoning now.
I have attempted to make one ajax call to the server and then use a MemoryProxy on each datastore to the returned result however i seem to be unsucessful as the datastore always seems to be empty, does anyone see a problem with the code below, or is there a better way of doing this.
Thanks in advance.
App.Customer= function(id, title) {
var mp = null;
var customerDs= null;
// retrieve data from the server
var load = function(){
Ext.Ajax.request({
url: 'borrower/data/id/'+id+'/',
callback: function(options, success, response){
if(success){
var data = Ext.decode(response.responseText);
mp = new Ext.data.MemoryProxy(data);
buildDataSources();
} else {
Ext.MessageBox.alert('Unknown Error', 'An unknown error occured while attempting to retreive the data, please contact a system administrator.');
}
},
scope: this
});
}
// build / load data stores.
var buildDataSources = function(){
// datastores
customerDs = new Ext.data.Store({proxy: mp,
reader: new Ext.data.JsonReader({root:'customers', id:'id'},
['id','company','leadsource','employee','title','firstname','middle','lastname',
'former','ssn','dob','permanent_street1','permanent_street2','permanent_city',
'permanent_state','permanent_zip','mailing_street1','mailing_street2','mailing_city',
'mailing_state','mailing_zip','primary_phone','secondary_phone','license_number',
'license_state','primary_email','secondary_email','createdate','fax','deleted',
'rtb','comments','active']),
remoteSort: false
});
customerDs.load();
}
load();
}
new App.Customer(15, "Firstname Lastname");
i believe this was a matter of callback scope, and execution order. either way i believe it to be funcitoning now.