Results 1 to 2 of 2

Thread: Data not getting saved in local storage

  1. #1
    Sencha User
    Join Date
    Nov 2012
    Location
    Mumbai, India
    Posts
    7
    Vote Rating
    0
      0  

    Default 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 - Sr Software Engineer mitchellsimoens's Avatar
    Join Date
    Mar 2007
    Location
    Gainesville, FL
    Posts
    39,326
    Answers
    3884
    Vote Rating
    1297
      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 @LikelyMitch
    Sencha Inc, Senior Software Engineer
    ________________
    Learn BBCode and use it!

    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.

Tags for this Thread

Posting Permissions

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