1. #1
    Sencha User
    Join Date
    Nov 2011
    Location
    England
    Posts
    135
    Answers
    11
    Vote Rating
    7
    george.m is on a distinguished road

      0  

    Default Unanswered: Dynamically-created Local Storage store not in StoreManager

    Unanswered: Dynamically-created Local Storage store not in StoreManager


    Hello all,

    I'm having a nightmare with local storage as I already have another post up related to LS.

    This one is about a dynamically-created store not being persistent. Elsewhere in my app, because I have a local storage store instantiated in the app.js store:[] section, this IS persistent on page refresh.

    However, when I try to load data into a store which is not being instantiated in the app.js store:[] section, I can't load the data after page refresh.

    Code:

    Model:
    Code:
    Ext.define('App.model.Region', {
        extend: 'Ext.data.Model',
           requires: ['Ext.data.identifier.Uuid'],
        config: {
            idProperty: 'auto',
            fields: ['id','buildingName','town','agent'],
            identifier: 'uuid'
        }
    });
    Store:
    Code:
    Ext.define('App.store.Region', {
        extend: 'Ext.data.Store',
        alias: 'store.region',
        requires: ['Ext.data.proxy.LocalStorage'],
        config: {
            storeId: 'region',
        model: 'App.model.Region',
            autoSave: false,
            syncRemovedRecords: false
           }
    });
    Store creation:
    Code:
    Ext.getStore('Store1').load({
    // Create localstorage store
    Ext.create('App.store.Region', {
         storeId: 'rg-46677',
         autoLoad: true,
         autoSave: true,
         proxy: {
              type: 'localstorage',
              storeId: 'rg-46677',
         }
    })
    regionStore = Ext.getStore('rg-46677');
    
    // Load data from Store1 into the localstorage store    
    Ext.each(this.getData().items, function(rec) {
          regionStore.add(rec);
    })
    regionStore.sync();
                        
    //Bind to list
    listComp.setStore(regionStore);
    })


    I'm assuming that it's because it is not getting registered in the StoreManager as it is not in Ext.data.StoreManager.all?

    Any help would be greatly appreciated.

    Thanks,
    George

    P.s.
    (I have also looked here http://www.sencha.com/forum/showthre...nd-persistency but I am already using that method).

  2. #2
    Sencha User
    Join Date
    Nov 2011
    Location
    England
    Posts
    135
    Answers
    11
    Vote Rating
    7
    george.m is on a distinguished road

      0  

    Default


    Sorry to bump the thread but it's grinding my gears now and could I do with the help.

    I've just upgraded from 2.0.1.1 to 2.1 and the problem is persisting.

  3. #3
    Sencha - Senior Forum Manager mitchellsimoens's Avatar
    Join Date
    Mar 2007
    Location
    Gainesville, FL
    Posts
    37,074
    Answers
    3500
    Vote Rating
    854
    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


    How are you requiring the store?
    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.

  4. #4
    Sencha User
    Join Date
    Nov 2011
    Location
    England
    Posts
    135
    Answers
    11
    Vote Rating
    7
    george.m is on a distinguished road

      0  

    Default


    Well I'm saving it in a localstorage store so that if the app is offline, it is still accessible. But like I said, the dynamically created store doesn't work on refresh, whereas the other store that is local storage which is in the Ext.application() store[] section is.

  5. #5
    Sencha - Senior Forum Manager mitchellsimoens's Avatar
    Join Date
    Mar 2007
    Location
    Gainesville, FL
    Posts
    37,074
    Answers
    3500
    Vote Rating
    854
    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


    If the store is in the stores array in Ext.application then an instance will be created automatically. It will either use the storeId config if one is present or create a storeId based on the class name.
    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.

  6. #6
    Sencha User
    Join Date
    Nov 2011
    Location
    England
    Posts
    135
    Answers
    11
    Vote Rating
    7
    george.m is on a distinguished road

      0  

    Default


    That's the problem, it isn't in the stores array.

    I have created a store called Region, which IS in the store array:

    Code:
    Ext.define('Audit.store.Region', {    extend: 'Ext.data.Store',
        requires: ['Ext.data.proxy.LocalStorage'],
            config: {
            model: 'Audit.model.Region',
            sorters: 'region',
            proxy: {
                type: 'localstorage',
                id: 'region-main'
            }
    }
    });

    Then in my view, I have a selectfield with different regions in, once I select a region, I make an ajax request to get a feed for that region. I then store this feed in a localstorage store by 'extending'(not sure if that is the write term) the original 'Region' store:

    Code:
    Ext.getStore('Region').setProxy( code here points to a file and gets the relevant feed ).load({
                                    // 'This is where I 'extend' that store already in the Ext.application store[] config
                                   // itemtosearch is a number that I use to load the relevant file
                        Ext.create('Audit.store.Region', {
                            storeId: 'rg-'+itemToSearch,
                            proxy: {
                                type: 'localstorage',
                                id: 'rg-'+itemToSearch
                            }
                        })
                        
                        regionStore = Ext.getStore('rg-'+itemToSearch);
                                    
                                    
                        Ext.each(this.getData().items, function(rec) {
                            var recToAdd = rec.data;
                            delete recToAdd['auto'];
                            delete recToAdd['id'];
                            console.log(recToAdd);
    
    
                            regionStore.add(recToAdd);
                        })
                    regionStore.sync();
    })
    It is this dynamically-created store that isn't saved. And I will have numerous stores like this.


    Should I just load all data into the store that is in the store:[] config and just filter it per region?

  7. #7
    Sencha - Senior Forum Manager mitchellsimoens's Avatar
    Join Date
    Mar 2007
    Location
    Gainesville, FL
    Posts
    37,074
    Answers
    3500
    Vote Rating
    854
    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


    This is working for me:

    Code:
    Ext.create('Ext.data.Store', {
        fields  : ['test'],
        storeId : 'test',
        proxy   : {
            type : 'localstorage',
            id   : 'test'
        }
    });
    
    console.log(Ext.getStore('test'));
    However, in your code you don't need to do the getStore call.
    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.

  8. #8
    Sencha User
    Join Date
    Nov 2011
    Location
    England
    Posts
    135
    Answers
    11
    Vote Rating
    7
    george.m is on a distinguished road

      0  

    Default


    Still isn't working for me, is it still there on refresh for you?

    I've changed it to the following but isn't playing ball still..

    Code:
    Ext.create('Ext.data.Store', {
    	model: 'Audit.model.Region',
    	storeId: 'rg-'+itemToSearch,
    	proxy: {
    		type: 'localstorage',
    		id: 'rg-'+itemToSearch
    	}
    })

Thread Participants: 1

Tags for this Thread