1. #1
    Sencha User
    Join Date
    Jun 2014
    Posts
    53
    Vote Rating
    0
    Answers
    6
    carlo123 is on a distinguished road

      0  

    Default Unanswered: LocalStorage Save Data immediately but at the next access I don't see any data

    Unanswered: LocalStorage Save Data immediately but at the next access I don't see any data


    Hi, I have this problem...I want to save Username and Password into localstorage for all the next accesses. The localstorage saves data immediately and I can work with it but at the next access I don't see any data. Can you help me please?

    Storage:
    Code:
    Ext.define('CiaoPoint.store.Config', {
        extend: 'Ext.data.Store',
    
        requires: [
            'CiaoPoint.model.config',
            'Ext.data.proxy.LocalStorage'
        ],
    
        config: {
            model: 'CiaoPoint.model.config',
            storeId: 'Config',
            syncRemovedRecords: false,
            proxy: {
                type: 'localstorage',
                id: 'userstoreproxy'
            }
        }
    });
    Model:
    Code:
    Ext.define('CiaoPoint.model.config', {
        extend: 'Ext.data.Model',
    
        requires: [
            'Ext.data.Field'
        ],
    
        config: {
            fields: [
                {
                    name: 'iduser'
                },
                {
                    name: 'Email'
                },
                {
                    name: 'GroupdId'
                },
                {
                    name: 'FollowText'
                },
                {
                    name: 'FbPage'
                },
                {
                    name: 'FbPostText'
                },
                {
                    name: 'DefaultFrame'
                },
                {
                    name: 'TermsCompany'
                },
                {
                    name: 'TermsMail'
                },
                {
                    name: 'TermsAddress'
                },
                {
                    name: 'TermsPlace'
                }
            ]
        }
    });
    Login Button(OnTap):
    Code:
    var me = this,
        loginForm = this.getLoginForm(),
        values = loginForm.getValues();
    var user = Ext.getCmp('username').getValue();
    var pwd = Ext.getCmp('password').getValue();
    
    me.logWrite('Login - Username:'+values.username);
    try {
        Ext.data.JsonP.request({
            url: 'http://ciaopoint.tecnitaliaopty.com/share/domusware/login.php',
            //method: 'post',
            params: { username:user/*, password:pwd*/ },
            //scope: this,
            callbackKey: 'callback',
            success: this.loginSuccess,
            failure: this.loginFailure
        });
    }  catch(err) {
            alert(err);
    }
    LoginSuccess Function:
    Code:
    var localStore = Ext.getStore('Config');
    
    if (result.success){
        
        localStore.getProxy().clear(); //lo pulisco ogni volta che faccio il login per non caricare piĆ¹ record
        localStore.add([{iduser:result.Id, //Aggiungo il record
                         Email:result.Email,
                         GroupdId:result.GroupdId,
                         FollowText:result.FollowText,
                         FbPage:result.FbPage,
                         FbPostText:result.FbPostText,
                         DefaultFrame:result.DefaultFrame,
                         TermsCompany:result.TermsCompany,
                         TermsMail:result.TermsMail,
                         TermsAddress:result.TermsAddress,
                         TermsPlace:result.TermsPlace
                        }]);
            localStore.sync(); //sincronizzo
    
            var recordPrimo = localStore.getAt(0);
    
    }
    else {
        alert('login fallito: ' +result.success);
    }
    In the Launch I insert this code to count the record of localstorage. Each Time that I Started the App the count say me 0:
    Code:
    var localStore = Ext.getStore('Config');
    var conta =   localStore.getCount();
    if ( conta === 1) {
         alert ('ok') ;
        } else {
         alert ('no' +conta) ;
        }

  2. #2
    Sencha User
    Join Date
    May 2011
    Location
    Gainesville, FL
    Posts
    180
    Vote Rating
    12
    Answers
    24
    fischer1121 is on a distinguished road

      0  

    Default


    Try adding autoLoad: true to your store's config. If you can post this to fiddle.sencha.com that will help us debug.

  3. #3
    Sencha User
    Join Date
    Jun 2014
    Posts
    53
    Vote Rating
    0
    Answers
    6
    carlo123 is on a distinguished road

      0  

    Default


    I already tried....doesn't function...have you other ideas....

  4. #4
    Sencha User
    Join Date
    May 2011
    Location
    Gainesville, FL
    Posts
    180
    Vote Rating
    12
    Answers
    24
    fischer1121 is on a distinguished road

      0  

    Default


    If you can post a fiddle, then we can fiddle with it

  5. #5
    Sencha User
    Join Date
    Jun 2014
    Posts
    53
    Vote Rating
    0
    Answers
    6
    carlo123 is on a distinguished road

      0  

    Default


    I don't understand the function....Can I give you a part of code with a file zip?

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


    Please verify in the browser developer tools that your localstorage gets populated.
    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.

  7. #7
    Sencha User
    Join Date
    Jun 2014
    Posts
    53
    Vote Rating
    0
    Answers
    6
    carlo123 is on a distinguished road

      0  

    Default


    I've found the issue. I'm using Architect and even if you remove content from idProperty in the model config, it stays there...with it...localStorage doesn't work. It is sufficient to put a blank ' ' in the idProperty config.