Extjs4 localstorage - How to delete all records?

The Local Storage proxy seems to be rather difficult in Extjs 4.1. Please tell me that I am doing something wrong.

I am trying (like others) to download data from a server and then store it locally for offline use. My problem is updating data (reloading in browser). removeAll() does not remove entries. I read that you can clear local storage by calling clear() on the local storage proxy. Although entries are deleted, the key generator does not reset. I am concerned that this will eventually cause a problem.

In my code, what am I doing, can this cause LocalStorage to malfunction? I know that there is some trick to setting the identifier on the model correctly, but I think I'm doing it right.

Here is the model and store:

  Ext.define('MAP.model.LookupData', { extend: 'Ext.data.Model', idProperty:'localId', fields: [ 'localId', // used for storing data via a localstorage proxy. -jg 'name', 'value' ] }); Ext.define('MAP.store.LocalCloudConditionStore', { extend: 'Ext.data.Store', model: 'MAP.model.LookupData', storeId: 'localCloudConditionStore', proxy: { type: 'localstorage', id : 'cloud-conditions' } }); 

Here the code tries to use removeAll() to clean up the local storage:

  offlineStore.load(); offlineStore.removeAll(); offlineStore.sync(); Ext.each(records,function(record){ var added = offlineStore.add(record.getData())[0]; console.log(added.get('id')); }); offlineStore.sync(); 

What the local memory proxy writes to my browser:

First load

And the second reboot. it does not delete the previous ones:

Second load. Frist load data isn't removed.

If I try to use proxy.clear() , the entries will disappear, but the idGenerator seed will not reset:

  offline.getProxy().clear(); Ext.data.StoreManager.register(offline); Ext.each(records,function(record){ var added = offline.add(record.getData())[0]; console.log(added.get('id')); }); offline.sync(); 

the counter isn't reset!

Thanks for your eyeballs.

UPDATE

I was able to reset the local store counter to directly reassign the value before creating an instance of my local store. Obviously, this is removed from the reservation, so it is not ideal.

 window.localStorage.setItem('cloud-conditions-counter',0); var offline = Ext.create('MAP.store.LocalCloudConditionStore'); offline.getProxy().clear(); 

DEUX UPDATE

Upon further thought, I think this is correct, not reset the counter. When a table in mysql is truncated, you will not reset the sequence number. This can cause problems if some cached identifier of the remote record was used to extract data from the table (let, for example, identifier 1). Instead of the one that was deleted, a completely different record will be returned. Ok, that makes sense.

And yet, why the hell isn’t working store.removeAll(); store.sync() store.removeAll(); store.sync() ?

+4
source share
1 answer

I am not sure if this is a mistake, but I am sure that removeAll() will not put the entries as deleted and will not affect the remote or local storage (i.e. the next synchronization will do nothing). This contrasts with remove() - it actually does.

You can use this method to delete all entries:

 Ext.override(Ext.data.Store), { removeAllForReal: function() { records = this.data.items, i = records.length; while (i--) { this.remove( records[i] ); } } }); 
+1
source

All Articles