1. #1
    Sencha User
    Join Date
    Oct 2010
    Location
    New Jersey USA
    Posts
    5
    Vote Rating
    0
    JesusJoseph is on a distinguished road

      0  

    Default Sencha Touch 2.0.1.1 Local Store not storing values

    Sencha Touch 2.0.1.1 Local Store not storing values


    Hi All,
    I am trying to store in the local storage and its not getting stored.
    I need to store two values as state id and license type as 1 record and next time I will update it. So the store will always has 1 record like below.

    Code:
    {
      'stateId': 'NJ',
      'licenseType': 'BDL'
    }
    I tried for the last 2 days and with different option but its not storing.
    Can someone please tell me what can be the problem in my code.



    Note: I am trying to test is using Chrome browser.

    Store Code
    Code:
    Ext.define("Sencha.store.TestParams", {    extend: "Ext.data.Store",
        requires: 
        [
            "Ext.data.proxy.LocalStorage"
        ],
        config: {
            model: "Sencha.model.TestParam",
            autoSync: true,
            proxy: {
                type: 'localstorage',
                id: 'ezdt-test-params'
            }
        }
    });
    Model Code
    Code:
    Ext.define("Sencha.model.TestParam",
    {
        extend: "Ext.data.Model",
        config:
        {
            idProperty: 'id',
            fields:
            [
                { name: 'id', type: 'int' },
                { name: 'stateId', type: 'string' },
                { name: 'licenseType', type: 'string' }
            ]
        }
    });
    Actual Code to save
    Code:
    var modTestParamInitialValues = Ext.create("Sencha.model.TestParam", {
                        id: 'ezdt', //Always Same as there will be only one record.
                        stateId: strSelectedState,
                        licenseType: strSelectedLicenseType
                    });
                    storTestParams.add(modTestParamInitialValues);
                    storTestParams.sync();
    Code I am using to retrieve the store value.
    Always its printing as Not Set
    Code:
    var storTestParams = Ext.getStore("TestParams");
            console.log("storTestParams#####-->" + storTestParams);
            //storTestParams.load();
            if(null != storTestParams)
            {
                var intTestParamCount = storTestParams.getCount();
                if(intTestParamCount == 0)
                { 
                               console.log("Not Set");
                            }
                            else
                { 
                               console.log("Set Correctly");
                            }
                    }
                    else
                   { 
                            console.log("Set Correctly");
                    }
    I hope I give all the details. If you need any more details please let me know.

    Thanks for your help.
    Joseph

  2. #2
    Sencha User
    Join Date
    Oct 2012
    Location
    Kortrijk, Belgium
    Posts
    16
    Vote Rating
    1
    wuytsr is on a distinguished road

      0  

    Default


    In your model, the ID field is set as an integer.

    When you create a model, you set 'ezdt' as the ID. But 'ezdt' is not an int, but a String. Maybe that's the problem.

    Try this in your model:
    Code:
    fields:         [             
    { name: 'id', type: 'auto' },             
    { name: 'stateId', type: 'string' },             
    { name: 'licenseType', type: 'string' }         ]
    Do you use the developper tool in chrome? (Ctrl-Shift-I)
    If not, you really should! Because in the "Resources" tab, you'll find all the Local Storage objects that are currently stored, and many other really helpfull features!

    This is the way I store an object in my LocalStorage:


    Code:
    console.log("Try to store something");
    
    
           
    
            userstore = Ext.getStore('LocalStorageUserStore');
                   
                
                var model = new App.model.LocalStorageUser({
                    id: '1',
                    user: "username",
                    pwd: "password"
                });
                var records = userstore.add(model);
                records[0].save();
    
            userstore.sync();
            
    
            var user = userstore.getAt(0).data.user;
            console.log(user);
            var pwd = userstore.getAt(0).data.pwd;
            console.log(pwd);
    I'm not saying this is the way you have to store something in your localstorage, but this code just works fine for me.
    Attached Images

  3. #3
    Sencha User
    Join Date
    Oct 2010
    Location
    New Jersey USA
    Posts
    5
    Vote Rating
    0
    JesusJoseph is on a distinguished road

      0  

    Default Error for the line records[0].save();

    Error for the line records[0].save();


    I use the same code and still I am getting the below error for the line records[0].save();
    Can you please tell me what proxy you use in the model.

    This is the code that I use to save the file.
    Code:
    var now = new Date();
            var noteId = (now.getTime()).toString() + (this.getRandomInt(0, 100)).toString();
    
    
            var newNote = Ext.create("NotesApp.model.Note", {
                id: noteId,
                dateCreated: now,
                title: "Joseph",
                narrative: "Joseph Desc"
            });
            var records = notesStore.add(newNote);
            records[0].save();
            notesStore.sync();

    Uncaught Error: [ERROR][NotesApp.controller.Notes#onSaveNoteCommand] You are trying to save a model instance that doesn't have a Proxy specified

  4. #4
    Sencha User
    Join Date
    Oct 2012
    Location
    Kortrijk, Belgium
    Posts
    16
    Vote Rating
    1
    wuytsr is on a distinguished road

      0  

    Default


    This is the code:
    Code:
    Ext.define(
    'App.model.LocalStorageUser', {
    
        extend: 'Ext.data.Model',
    
        alias: 'widget.LocalStorageUser',
    
        config: {
    
            idProperty: 'id',
    
            fields: [
    
                 { name: "id", type: "auto" },
    
                { name: "user", type: "string" },
    
                {name: "pwd", type:"string"}
    
            ],
    
            proxy: {
    
                type: 'localstorage',
    
                id: 'users'
    
            }
    
        }
    
    });
    

Thread Participants: 1

Tags for this Thread

Turkiyenin en sevilen filmlerinin yer aldigi xnxx internet sitemiz olan ve porn sex tarzi bir site olan mobil porno izle sitemiz gercekten dillere destan bir durumda herkesin sevdigi bir site olarak tarihe gececege benziyor. Sitenin en belirgin ozelliklerinden birisi de Turkiyede gercekten kaliteli ve muntazam, duzenli porno izle siteleri olmamasidir. Bu yuzden iste. Ayrica en net goruntu kalitesine sahip adresinde yayinlanmaktadir. Mesela diğer sitelerimizden bahsedecek olursak, en iyi hd porno video arşivine sahip bir siteyiz. "The Best anal porn videos and slut anus, big asses movies set..." hd porno faketaxi