1. #1
    Sencha User
    Join Date
    Aug 2012
    Posts
    2
    Vote Rating
    0
    MeMTn is on a distinguished road

      0  

    Default Answered: Save the Store data to LocalSotrage !

    Answered: Save the Store data to LocalSotrage !


    hi,

    I am new to sencha touch, I was beating my head against the wall for the last couple of days to solve this problem without any result .

    I have a storage named articles that gets its data from a server (using an ajax proxy), and I pass this store to an ArticleList view that displays it, and this works as wanted but now i want the data of "store.Articles" to be saved to LocalStorage automatically, and when I reload my app i want the view to use the data stored in the localStorage in stead of loading it again from the server.

    any suggestions on how i can solve this problem.

    here is my code:

    myApp/model/Article.js:

    Code:
    Ext.define('myApp.model.Article', {    extend: 'Ext.data.Model',
        
        config: {
            fields: [
                {
                    name: 'nid'
                    //, type: 'string'
                },
                {
                  name: 'Id'
                },
                {
                    name: 'title'
                    //, type: 'string'
                },
                {
                    name: 'uid'
                //, type: 'string'
                },
                {
                    name: 'uri'//, type: 'string'
                }
            ]
        }
    });
    myApp/sotre/Articles.js:

    Code:
    Ext.define('myApp.store.Articles',{    extend: 'Ext.data.Store',
            requires: [
            'myApp.model.Article'
        ],
    
    
        config:{
            autoLoad: true,
            autoSync : true,
            model: 'myApp.model.Article',
            storeId: 'Articles',
    
    
            proxy : {
                type : 'ajax',
                method: 'GET',
                url : 'http://myserver/services/articles',
                enablePagingParams : false,
                reader : {
                    type : 'json'
                }
            }
        }
    });
    myApp/view/ArticlesList.js :

    Code:
    Ext.define('myApp.view.ArticlesList',{    extend : 'Ext.dataview.List',
        xtype: 'ArticlesList',
    
    
        config : {
            store: "Articles",
            itemTpl: [
                '{nid} - {title}'
                ]
        }
    
    
    });

    thanks in advance,

  2. You could change the store to local storage. Then, write a nice piece of script which 1) reads al records which has to be inserted (in JSON format for example) 2) insert those records into the store and 3) saves the date/time of last synchronization, which can be used for further synchronisation.

    Make sure that (in the model) you explicitly specify the identifier (UUID) and idproperty, otherwise local storage will not work correctly.

    So change the proxy in your store to:
    PHP Code:
    proxy: {            type'localstorage',            id'Articles'         
    Add those line in your model's config:
    PHP Code:
    idProperty'appid',
    identifier'uuid' 
    You will have to think about the synchronization part yourself, as that depends on what functionality you want.

  3. #2
    Sencha Premium Member
    Join Date
    Dec 2009
    Posts
    16
    Answers
    2
    Vote Rating
    1
    mdb is on a distinguished road

      1  

    Default


    You could change the store to local storage. Then, write a nice piece of script which 1) reads al records which has to be inserted (in JSON format for example) 2) insert those records into the store and 3) saves the date/time of last synchronization, which can be used for further synchronisation.

    Make sure that (in the model) you explicitly specify the identifier (UUID) and idproperty, otherwise local storage will not work correctly.

    So change the proxy in your store to:
    PHP Code:
    proxy: {            type'localstorage',            id'Articles'         
    Add those line in your model's config:
    PHP Code:
    idProperty'appid',
    identifier'uuid' 
    You will have to think about the synchronization part yourself, as that depends on what functionality you want.

  4. #3
    Sencha User
    Join Date
    Aug 2012
    Posts
    2
    Vote Rating
    0
    MeMTn is on a distinguished road

      0  

    Default


    thanks a lot this worked perfectly

Thread Participants: 1

Tags for this Thread

Turkiyenin en sevilen filmlerinin yer aldigi xnxx internet sitemiz olan ve porn sex tarzi bir site olan mobil porno izle sitemiz gercekten dillere destan bir durumda herkesin sevdigi bir site olarak tarihe gececege benziyor. Sitenin en belirgin ozelliklerinden birisi de Turkiyede gercekten kaliteli ve muntazam, duzenli porno izle siteleri olmamasidir. Bu yuzden iste. Ayrica en net goruntu kalitesine sahip adresinde yayinlanmaktadir. Mesela diğer sitelerimizden bahsedecek olursak, en iyi hd porno video arşivine sahip bir siteyiz. "The Best anal porn videos and slut anus, big asses movies set..." hd porno faketaxi