Getting LocalStorageProxy working with TreeStore

There,

I am creating an iPhone Sencha Touch application that uses a TreeStore that works great with a NestedList, but I hit a wall.

He needs a way to read data in a static store (TreeStore), load it into localStorage so that it is writable, and then save some user settings. I realized that localStorageProxy is most likely what I need (I was relieved to find that I do not need to serialize and deserialize the JSON store manually!), But after reading the documentation on it and trying and crashing a few things, I'm at a loss .

Be that as it may, it generates localStorage storage ... but it is empty, I think this is because I did not load anything into it, but when I run it, the app.stores.event_store.load();screen is empty and the Console shows that localStorage is empty, without error.

My model:

Ext.regModel ('Events', {
    fields: [
        {name: 'text', type: 'string'},
        {name: 'info', type: 'string'},
        {name: 'attend', type: 'boolean', defaultValue: 'false'}
    ]   
});

My shop:

app.stores.event_store = new Ext.data.TreeStore ({
    model: 'Events',
    root: data,
    storeId: 'eventStoreId',
    proxy: {
        type: 'localstorage',
        id: 'eventsAttending',
        url: 'store.js',
        reader: {
            type: 'tree',
            root: 'items'
        }
    }
});

app.stores.event_store.load();

, , , - , ​​.

GitHub.

-fetimo

+3
1

TreeStore

var data= { 
    text: 'Groceries',
    items: [{
        text: 'Drinks',
        items: [{
            text: 'Water',
            items: [{
                text: 'Sparkling',
                leaf: true
            },{
                text: 'Still',
                leaf: true
            }]
        },{
            text: 'Coffee',
            leaf: true
        }]
    }] 
}

LocalStorageProxy .

AJAX store.js, localStorage, "" .

Ext.Ajax.request({
    url: 'store.js',
    success: function(response, opts) {
       localStorage.StoreJSBlob = response.responseText;
    }
});

:

var store = new Ext.data.TreeStore({
    model: 'Events',
    root: localStore.StoreJSBlob,
    proxy: {
        type: 'ajax',
        reader: {
            type: 'tree',
            root: 'items'
        }
    }
});

, .

+3
source

All Articles