PDA

View Full Version : Can i use localstorage in nestedlist?



japanSencha
1 Aug 2012, 11:59 PM
Hi mates,

Can i use localstorage in nestedlist?

I don't have a problem on saving localstorage to textfield but when
i try to use it to nestedlist, this will not work. I know, its not
working because localstorage is only textfield or something not nestedlist,
is there any workaround?

something like this
http://www.sencha.com/forum/showthread.php?181461-Add-localstorage-to-a-nested-list

kostysh
3 Aug 2012, 10:38 AM
Of course you can, but with some headache because localStorage proxy not support nested data.
For now you should store/restore JSON with nested data simply by localStorage.setItem/getItem and dynamically create TreeStore from this JSON for nestedlist.

japanSencha
5 Aug 2012, 8:41 PM
@kostysh (http://www.sencha.com/forum/member.php?339050-kostysh)

thanks for your reply. I thinks it easy to understand if you can give me a sample file or a snippet for dynamic treestore.

Or a sample file for an online/offline mode using localStorage with xtype nestedList. Honestly, I don't know how to solve this issue, I've searched google but only advices, I want samples so that I'll know if it's working or not.

Casper Alant
15 Dec 2012, 12:08 AM
I know this is probably to late but I had this problem and couldn't find a solution anywhere. So for anyone else who comes across this problem, here is my solution. It is not the most elegant, but it works.



update: function() {
if ((!Ext.device.Connection.isOnline())&&(false)) {
Ext.Msg.alert('You are not currently connected.');
} else {

var serverStore = Ext.getStore('ServerPapersTreeStore');
console.log('The localStore is being updated.');
var controller = this;
serverStore.load({
callback: function(records, operation, success) {

var localStore = Ext.getStore('LocalPapersStore');
localStore.load({
callback: function(records, operation, success) {

this.tree = serverStore.getProxy().getReader().rawData;
localStore.removeAll();
localStore.add({items: Ext.encode(serverStore.getProxy().getReader().rawData)});
localStore.sync();
console.log('localStore has been updated.');
controller.updateVersion();


},
scope: this
});


},
scope: this
});
}
},


var localStore = Ext.getStore('LocalPapersStore'); localStore.load({
callback: function(records, operation, success) {
console.log('localStore has been loaded.');
if(typeof records[0] !== "undefined") {
this.tree = Ext.decode(records[0].get('items'));
}


},
scope: this
});


loadNavigatePapersList: function() { Ext.Viewport.removeAll();
console.log('loadNavigatePapersList');
if(this.storeRegistered){
console.log('Store must be reset.');
Ext.getStore('LocalPapersTreeStore').setData(this.tree);

} else {
var treeStore = Ext.create('ED.store.PapersTreeStore', {
root: this.tree,
storeId: 'LocalPapersTreeStore'
});
}
this.storeRegistered=true;
Ext.widget('navigatepaperslist').show();
},