1. #1
    Sencha User
    Join Date
    Oct 2012
    Posts
    11
    Vote Rating
    0
    josser is on a distinguished road

      0  

    Default Answered: Cant get data from data.proxy.localstorage

    Answered: Cant get data from data.proxy.localstorage


    Hi,

    I'm trying to use localstorage proxy for my models, but for some reason after each page refresh I have empty data.
    I'm debuging in google chrome + ripple, and inside the "Storage" tab, I can see all data I saved. But when I trying to read it - data is empty.

    Here the code:

    controllers/Main.js:
    Code:
    launch: function() { 
    
     var optionsStore = Ext.getStore('optionsStore'),
        currentType = optionsStore.getById('type'); // Is null :( I event can't call .get() because it is null. 
    }
    Saving:
    Code:
    optionsStore.setData([{
            key: 'type',
            value: 'posts'
    }]);
    Reading after saving is ok.

    Store and model:
    Code:
    Ext.define('PM.model.Option', {
      extend: 'Ext.data.Model',
      requires: ['Ext.data.proxy.LocalStorage'],
      config: {
        fields: [
          { name: 'value', type: 'auto'}
        ],
        idProperty: 'key',
        proxy: {
          type: 'localstorage',
          id: 'options'
        }
      }
    });
    
    
    Ext.define('PM.store.Options', {
      extend: 'Ext.data.Store',   
      config: {
        model: 'PM.model.Option',
        storeId: 'optionsStore',
        autoSync: true
      }
    });

    Maybe I miss some addiitonal initialization code?

    Thanks and sorry for my bad english

  2. Can you let your store load the data at first?
    Code:
    var optionsStore = Ext.getStore('optionsStore'),
        currentType;
    console.info(optionsStore.isLoaded());
    optionsStore.load(function(){
        currentType=optionsStore.getById('type');
    })

  3. #2
    Sencha User
    Join Date
    Apr 2010
    Location
    China
    Posts
    227
    Vote Rating
    20
    Answers
    64
    haduki will become famous soon enough haduki will become famous soon enough

      0  

    Default


    Can you let your store load the data at first?
    Code:
    var optionsStore = Ext.getStore('optionsStore'),
        currentType;
    console.info(optionsStore.isLoaded());
    optionsStore.load(function(){
        currentType=optionsStore.getById('type');
    })
    I write English by translator.

  4. #3
    Sencha User
    Join Date
    Oct 2012
    Posts
    11
    Vote Rating
    0
    josser is on a distinguished road

      0  

    Default


    Works like a charm!

    This should be in docs, thank you very much!

Thread Participants: 1

Tags for this Thread