1. #1
    Sencha User
    Join Date
    May 2012
    Posts
    3
    Vote Rating
    0
    raptors2k4 is on a distinguished road

      0  

    Default Unanswered: Store with multiple fields problem with localstorage proxy

    Unanswered: Store with multiple fields problem with localstorage proxy


    I've got the following proxy used to display tweets:

    Code:
            Ext.define('tweetModel',{
                extend:'Ext.data.Model',
                config:{
                    fields: ['from_user', 'profile_image_url', 'text', 'created_at']
                }
            });
    
            Ext.define('TweetStore2', {
                extend: 'Ext.data.Store',
                config: {
                    model: 'tweetModel',
    
                    storeId: 'myTweetStore',
                    pageSize: 20,
                    autoLoad: true,
                    autoSync: true,
                    
                    proxy: new Ext.data.LocalStorageProxy({
                        id: 'twsavedata',
                        proxy:{idProperty: 'id'}
                    })
                    //proxy: {
                    //    type: 'localstorage',
                    //    id: 'twsaveddata'
                    //}
                }
            });
    Both proxy store declarations produced the same results - the key is getting stored in localstorage (twsavedata) but value is empty. The number of tweets is relatively low, so I'm wondering if there is a known limitation with store localstorage proxy only working for single field models... The model data gets updated, as I see it on screen, so that is not the problem.

    Thanks for your help.
    Last edited by raptors2k4; 3 May 2012 at 7:49 AM. Reason: Explain there is actual data in the store...

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


    There is no limitation at all. You should uncomment the proxy config and remove the one you have in there though.
    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.

  3. #3
    Sencha User
    Join Date
    May 2012
    Posts
    3
    Vote Rating
    0
    raptors2k4 is on a distinguished road

      0  

    Default


    Quote Originally Posted by mitchellsimoens View Post
    There is no limitation at all. You should uncomment the proxy config and remove the one you have in there though.
    Thanks for your help Mitchell. Even with changing the store definition to:

    Code:
            Ext.define('tweetModel',{
                extend:'Ext.data.Model',
                config:{
                    fields: ['text']
                }
            });
    
            Ext.define('TweetStore2', {
                extend: 'Ext.data.Store',
                config: {
                    model: 'tweetModel',
    
                    storeId: 'myTweetStore',
                    pageSize: 20,
                    autoLoad: true,
                    autoSync: true,
                    
                    //proxy: new Ext.data.LocalStorageProxy({
                    //    id: 'jbsavedata',
                    //    proxy:{idProperty: 'id'}
                    //})
                    proxy: {
                        type: 'localstorage',
                        id: 'jbsaveddata'
                    }
                }
            });
    , storing only one field (tweet text) and having the following code to insert items into the store (from a remote store's load listener, which is reloaded periodically):

    Code:
           localStore.insert(insertPos++,remoteRecord);
           console.log(localStore.first());
           localStore.sync();
           localStore.last().commit();
    , I still don't see any data being saved locally in chrome. I used another site and it is able to save to window.localStorage (quite a lot of data actually). Through Ext.List I am able to see the store data, and records are being inserted (so autoSync should have saved the data locally). Do you have any code examples with autosync-ing stores that I could run to see what I get? I hate for this to be a browser issue :-)

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


    Here is a test that I tested with 2.0.1 on Chrome 18 and works just fine:

    Code:
    Ext.define('TestModel', {
        extend : 'Ext.data.Model',
    
        config : {
            identifier : 'uuid',
            fields     : [
                'test'
            ]
        }
    });
    
    var store = new Ext.data.Store({
        autoLoad  : true,
        autoSync  : true,
        model     : 'TestModel',
        proxy     : {
            type : 'localstorage',
            id   : 'test'
        },
        listeners : {
            load : function (s) {
                console.log('Data loaded, store has ' + s.getCount() + ' items');
            }
        }
    });
    
    new Ext.Container({
        fullscreen : true,
        items      : [
            {
                xtype   : 'button',
                text    : 'Add Data',
                handler : function () {
                    store.add([
                        { test : 'One'   },
                        { test : 'Two'   },
                        { test : 'Three' }
                    ]);
                    //store.sync();
    
                    console.log('Data added, store has ' + store.getCount() + ' items');
                }
            },
            {
                xtype   : 'button',
                text    : 'Remove First Record',
                handler : function () {
                    var rec = store.getAt(0);
                    store.remove(rec);
                    //store.sync();
    
                    console.log('First record removed, store has ' + store.getCount() + ' items');
                }
            },
            {
                xtype   : 'button',
                text    : 'Clear Data',
                handler : function () {
                    store.removeAll();
                    //store.sync();
    
                    console.log('Data cleared, store has ' + store.getCount() + ' items');
                }
            },
            {
                xtype   : 'button',
                text    : 'Console Record Data',
                handler : function () {
                    console.log('Record data:');
    
                    store.each(function (record) {
                        console.log(record.getData());
                    });
                }
            }
        ]
    });
    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.

  5. #5
    Sencha User
    Join Date
    May 2012
    Posts
    3
    Vote Rating
    0
    raptors2k4 is on a distinguished road

      0  

    Default


    Hmm, I'll try to fiddle with it later (and try Sencha Touch 2.0.1), but I only see "Data loaded, store has 0 items" on line 22 (the store load listener). I'm using the development microloader.js and sencha-touch-all.js (v2.0.0-commercial). Tried on both Chrome 18.0.1025.168m and Firefox 12.0.

    EDIT: Using same resources from 2.0.1 didn't resolve the issue - still see nothing saved with my store, and nothing past the store creation in your script. I feel I'm missing some files (I started this example off the pullrefresh example), but I see no errors in console :\ .. Can you give me a zip of whatever is working for you, and I'll test it over here - replacing my app.js with yours above did not work for me, as I mentioned above. Thanks.

Thread Participants: 1

Tags for this Thread