PDA

View Full Version : Store.remove using LocalStorage proxy not working for me



JacobGu
29 Dec 2010, 5:54 AM
My app periodically refreshes a data store of employee records using a LocalStorage proxy. Each refresh, if I call the remove method on entire record range, it does not remove the records (at least synchronously), and then will cause records to be duplicated each refresh (1x, 2x, 3x, 4x, etc.). What I did as a workaround was access localStorage object directly to remove the data and then reload store from localStorage.

This is a code excerpt:



TC.DeleteLocalStorageThatBeginsWith('tcEmployeeCache');
//TC.employeeCache.remove(TC.employeeCache.getRange()); // not removing records for some reason
TC.employeeCache.load();
TC.employeeCache.add(pingResult.employees);
TC.employeeCache.sync();

TC.DeleteLocalStorageThatBeginsWith = function(keyPrefix){
var len = localStorage.length;
// reverse iterate collection to allow inline removal
for(var i = len-1; i >= 0; i--){
var key = localStorage.key(i);
if(key.indexOf(keyPrefix) == 0){
localStorage.removeItem(key);
}
}
}


Is this an issue of asynchronous removal? What is the correct way to do this within Sencha API?

Thanks.

chummy
30 Dec 2010, 1:21 PM
My reply to this thread (http://www.sencha.com/forum/showthread.php?119745-LocalStorage-for-Application-Settings-and-remove) might help.

Chummy

JacobGu
30 Dec 2010, 1:41 PM
You are absolutely correct! Adding an id fixed the problem. Looks like a Sencha bug, either in code or in documentation of the 'id' field.