1. #1
    Sencha User
    Join Date
    Jul 2012
    Posts
    1
    Vote Rating
    0
    maxsqr is on a distinguished road

      0  

    Default Unanswered: Yet another question about Localstorage

    Unanswered: Yet another question about Localstorage


    Hello,

    I have problems with saving or loading data to/from localstorage. After adding record, I can view it in the dataview. But when I'm restarting application there is no data, also if I use myStore.load() function to reload data in dataview, it will not load any data from localstorage and will nullify store.

    adding new record:
    Code:
    var myStore= Ext.data.StoreManager.lookup('MyImageStore');
    myStore.add({id:(max+1),caption:cap,name:idName,date:dat,path:local_path});
    myStore.sync();
    my store:
    Code:
    Ext.define('ws.store.MyImageStore', {
        extend: 'Ext.data.Store',
        xtype: 'MyImageStore',
        requires: 'ws.model.ImageModel',
        config: {
            model: 'ws.model.ImageModel',        
            proxy: {
                type: 'localstorage',
                id  : 'myImageLocalstorage'            
            } 
        },
        autoLoad: true
    });
    dataview:
    Code:
    Ext.define('ws.view.Nav', {
        extend: 'Ext.DataView',    
        xtype: 'Nav',
        
        config: {
            store: 'MyImageStore',
        
            itemTpl: '<div>{name}|{caption}|{date}|{path}</div>'
        }
    });
    and refresh function:
    Code:
    var datav=Ext.getCmp("Nav");
    datav.refresh();

  2. #2
    Sencha - Community Support Team jay@moduscreate.com's Avatar
    Join Date
    Mar 2007
    Location
    DC Area =)
    Posts
    16,364
    Vote Rating
    81
    Answers
    102
    jay@moduscreate.com is a name known to all jay@moduscreate.com is a name known to all jay@moduscreate.com is a name known to all jay@moduscreate.com is a name known to all jay@moduscreate.com is a name known to all jay@moduscreate.com is a name known to all

      0  

    Default


    Welcome to the forums .

    Here are some suggestions:

    1) STOP using static IDs
    2) you need to use store.add() to add an instance of a model, not a plain object.
    3) local storage proxies need to be setup on the model, not the store.
    4) Look at the LocalStorage proxy for an example: http://docs.sencha.com/touch/2-0/#!/...y.LocalStorage
    it works perfectly.

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


    Quote Originally Posted by jay@moduscreate.com View Post
    2) you need to use store.add() to add an instance of a model, not a plain object.
    If you use a config object like the OP does it will create the model instance (record) and add that so it's still very much valid to do like he did:

    Code:
    myStore.add({
        id      : (max + 1), 
        caption : cap, 
        name    : idName, 
        date    : dat, 
        path    : local_path
    });
    Quote Originally Posted by jay@moduscreate.com View Post
    3) local storage proxies need to be setup on the model, not the store.
    Matter of preference for local storage, very much valid to put it on 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.