Forum /
Sencha Touch 2.x Forums /
Sencha Touch 2.x: Q&A /
Unanswered: Resetting store's Proxy from localStorage to AjaxProxy
Unanswered: Resetting store's Proxy from localStorage to AjaxProxy
I wanted to check the saved record from the local storage and authenticate the record with the server. I tried to change the store proxy using the function setProxy. First time when i call setProxy on the store it works fine however when i call it second time with a different Proxy, it throws error "Cannot call method 'getRecords' of undefined" . Below is the logic.
localProxy = this.local = Ext.create('Ext.data.proxy.LocalStorage', {id:'credentials'});
store.setProxy(localProxy);
...
serverProxy = Ext.create('Ext.data.proxy.Ajax', { url: 'xxx',
type:'json',
});
store.setProxy(serverProxy);
on executing this statement, it throws error "Cannot call method 'getRecords' of undefined"
Any help is much appreciated.
Thanks,
John
This is absolutely a problem with setProxy when switching between local and ajax proxies.
Ext.apply.factory checks
if ( instance && instance !== config ) {
Where instance is your old proxy (the one your switching out of) and config is your new one (the one your requesting set in the setProxy call).
If they're not equal (they aren't), it runs
instance . destroy ();
The destroy method
destroy: function (operation, callback, scope) {
var records = operation.getRecords(),
Attempts to immediately initialize records via operation.getRecords(), however there is no operation passed to the destroy function.
I believe the problem may be user error.
I was seeing this error when doing
//Original REST proxy
var swap = this.getProxy();
//localProxy: { type:'localstorage; id: 'foo'; }
//...defined in the Model config
this.setProxy(this.getLocalProxy());
//Restoring the original proxy
this.setProxy(swap);
Though this appears correct/straightforward, the last line should actually read
//Restoring the original proxy
this.setProxy(swap.config);
This eliminated the error above.
Sencha is used by over two million developers. Join the community, wherever you’d like that community to be
or Join Us