Results 1 to 4 of 4

Thread: Can i use localstorage in nestedlist?

  1. #1
    Sencha Premium Member
    Join Date
    Apr 2012
    Posts
    77
    Vote Rating
    1
      0  

    Default Can i use localstorage in nestedlist?

    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/showthre...-a-nested-list

  2. #2
    Sencha User kostysh's Avatar
    Join Date
    Nov 2011
    Location
    Odessa, Ukraine
    Posts
    176
    Vote Rating
    20
      0  

    Default

    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.

  3. #3
    Sencha Premium Member
    Join Date
    Apr 2012
    Posts
    77
    Vote Rating
    1
      0  

    Default

    @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.

  4. #4
    Sencha User
    Join Date
    Sep 2012
    Posts
    8
    Vote Rating
    1
      0  

    Default How to use treestore with localstorage

    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.


    Code:
    	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
    		});
    		}
    	},
    Code:
    		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
    						});
    Code:
        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();
        },

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •