Results 1 to 3 of 3

Thread: Yet another question about Localstorage

  1. #1
    Sencha User
    Join Date
    Jul 2012
    Posts
    1
    Vote Rating
    0
      0  

    Default 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 User jay@moduscreate.com's Avatar
    Join Date
    Mar 2007
    Location
    DC Area =)
    Posts
    16,364
    Answers
    102
    Vote Rating
    87
      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 - Sr Software Engineer mitchellsimoens's Avatar
    Join Date
    Mar 2007
    Location
    Gainesville, FL
    Posts
    39,316
    Answers
    3881
    Vote Rating
    1291
      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 @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
  •