pex
24 Apr 2007, 11:22 AM
Hello,
I have a bit of a complex situation here, the problem is as follows. I have multiple comboboxes on my page which all use the same DataStore. This is a remote datastore, and the combobox uses lazyRender. Everytime a user clicks on 1 of the comboboxes the dataStore gets triggered and fires a http POST request to fetch the data... however, what I want is some sort of caching where the dataStore only retrieves the records once, stores them in memory and all subsequent calls use this memory cache.
So I embarked on a singleton journey. In this singleton I store my data:
Ext.namespace('Ext.testData');
Ext.testData = function(){
return {
getCountries: function(){
if (this.s) { return this.s; }
this.s = new Ext.data.Store({
proxy: new Ext.data.HttpProxy({
url: 'countries.php'
}),
reader: new Ext.data.JsonReader({
root: 'data',
totalProperty: 'total'
}, [
{name: 'code', mapping:'code'},
{name: 'name', mapping:'name'}
])
});
return this.s;
}
};
}();
Next in my comboBox code I use
var combo = new Ext.form.ComboBox({
store: Ext.testData.getCountries(),
displayField:'code',
valueField:'code',
typeAhead: true,
mode: 'remote',
triggerAction: 'all',
emptyText:'Select',
selectOnFocus:true,
lazyRender:true
});
Now my idea was whenever I make a comboBox the store would only be called once, since it's stored in a singleton. THis is true, however the OBJECT is stored in memory, not the data. So the HTTP POST is still triggered everytime I click on a combobox. Is there a way to make the data from the store local once it's receieved from the server?? or is there an other way to solve this problem? Im open to any ideas!
Thanks!
I have a bit of a complex situation here, the problem is as follows. I have multiple comboboxes on my page which all use the same DataStore. This is a remote datastore, and the combobox uses lazyRender. Everytime a user clicks on 1 of the comboboxes the dataStore gets triggered and fires a http POST request to fetch the data... however, what I want is some sort of caching where the dataStore only retrieves the records once, stores them in memory and all subsequent calls use this memory cache.
So I embarked on a singleton journey. In this singleton I store my data:
Ext.namespace('Ext.testData');
Ext.testData = function(){
return {
getCountries: function(){
if (this.s) { return this.s; }
this.s = new Ext.data.Store({
proxy: new Ext.data.HttpProxy({
url: 'countries.php'
}),
reader: new Ext.data.JsonReader({
root: 'data',
totalProperty: 'total'
}, [
{name: 'code', mapping:'code'},
{name: 'name', mapping:'name'}
])
});
return this.s;
}
};
}();
Next in my comboBox code I use
var combo = new Ext.form.ComboBox({
store: Ext.testData.getCountries(),
displayField:'code',
valueField:'code',
typeAhead: true,
mode: 'remote',
triggerAction: 'all',
emptyText:'Select',
selectOnFocus:true,
lazyRender:true
});
Now my idea was whenever I make a comboBox the store would only be called once, since it's stored in a singleton. THis is true, however the OBJECT is stored in memory, not the data. So the HTTP POST is still triggered everytime I click on a combobox. Is there a way to make the data from the store local once it's receieved from the server?? or is there an other way to solve this problem? Im open to any ideas!
Thanks!