1. #1
    Sencha User
    Join Date
    Nov 2012
    Location
    Mumbai, India
    Posts
    7
    Vote Rating
    0
    sirwanimayur is on a distinguished road

      0  

    Default Unanswered: Data not getting saved in local storage

    Unanswered: Data not getting saved in local storage


    here is my model

    Code:
    Ext.define('OfferDrive.model.StoreCategories',{
    	extend:'Ext.data.Model',
    	config:{
    		idProperty: 'Id',
    		fields:[
    			{name: 'Id', type: 'int'},
    			{name: 'Name', type: 'string'}
    		]
    	}
    });
    here is my store

    Code:
    Ext.define("OfferDrive.store.CategoryStore", {
        extend: "Ext.data.Store",
        requires: "Ext.data.proxy.LocalStorage",
        config: {
            model: "OfferDrive.model.StoreCategories",
            proxy: {
                type: 'localstorage',
                id: 'favorite-category-store'
            }
        }
    });
    This is my button tab event
    Code:
    listeners:{
    				tap: function(){
    					var categoryList = Ext.ComponentManager.get('categoryList');		
    					var favCategoriesStore = Ext.getStore('CategoryStore');
    					
    					for (var i=0; i< categoryList.config.store.data.items.length; i++)
    					{ 
    						if(categoryList.config.store.data.items[i].data.CheckUrl.indexOf("Golden") != -1){
    							var record = favCategoriesStore.findRecord('Id', categoryList.config.store.data.items[i].data.Id)
    							if (null == record){
    								//insert
    								var newFavorite = Ext.create("OfferDrive.model.StoreCategories", {
    									Id: categoryList.config.store.data.items[i].data.Id,
    									Name: categoryList.config.store.data.items[i].data.Name
    								});
    								favCategoriesStore.add(newFavorite);
    								favCategoriesStore.sync();
    								alert('added');
    							}
    						}else{
    							var record = favCategoriesStore.findRecord('Id', categoryList.config.store.data.items[i].data.Id)
    							if (null != record){
    								//remove
    								favCategoriesStore.remove(record);
    								favCategoriesStore.sync();
    								alert('removed');
    							}
    						}
    					}
    					Ext.ComponentManager.get('catListModal').destroy();
    				}
    			}
    The data is lost as soon as the page is refreshed, I cant even see the data on my chrome developer tools local storage section, I just see the table name, no data inside it

  2. #2
    Sencha - Senior Forum Manager mitchellsimoens's Avatar
    Join Date
    Mar 2007
    Location
    Gainesville, FL
    Posts
    37,525
    Vote Rating
    871
    Answers
    3564
    mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute

      0  

    Default


    There is an open bug that if your data has a value for the idProperty and it won't sync to localstorage.
    Mitchell Simoens @SenchaMitch
    Sencha Inc, Senior Forum Manager
    ________________
    Check out my GitHub, lots of nice things for Ext JS 4 and Sencha Touch 2
    https://github.com/mitchellsimoens

    Think my support is good? Get more personalized support via a support subscription. https://www.sencha.com/store/

    Need more help with your app? Hire Sencha Services services@sencha.com

    Want to learn Sencha Touch 2? Check out Sencha Touch in Action that is in print!

    When posting code, please use BBCode's CODE tags.