1. #1
    Sencha User
    Join Date
    Aug 2011
    Location
    Mumbai, India
    Posts
    119
    Vote Rating
    4
    Answers
    11
    Sasha172 is on a distinguished road

      0  

    Default Answered: Stop overwriting data in store

    Answered: Stop overwriting data in store


    Hi,
    My app is a list of ToDo's of forms that need to be completed.

    1. When the app is opened, it goes to the server and collects (from a database) a list of forms to be completed.
    2. When you click on a form you can then fill in the data (using LocalStorage proxy) and then save/update the data. The data is stored locally on the device.

    As of now : When I open the app again, it collects the same list of ToDo's and overwrites the data in the LocalStorage (ie my filled up forms) with new empty forms and therefore I need to fill them again.

    What I want : Instead of overwriting filled up forms I need to only collect those forms that are not already in my localstorage.

    My Code :
    Store :-
    Code:
    FMS.stores.onlineTodo =  new Ext.data.Store({
        model: 'ToDoMod',
        proxy: {
            id : 'fmsonlinetodo',
            type: 'ajax',
            url: 'app/data/dummydata.json',
            reader: new Ext.data.JsonReader({
                root: 'items'
            }),
            timeout: 2000,
            listeners: {
                exception:function () {
                    console.log("I think we are offline");
                    flagoffline = 1;
    //              
                }
            }
        }
    });
    Code:
    FMS.stores.offlineTodo = new Ext.data.Store({
        model : 'ToDoMod',
        proxy : {
            type : 'localstorage',
            id : 'fmsofflinetodo'
        }
    });
    Controller function that loads data into store :
    Code:
    loadDataInitial : function(){
            
            FMS.stores.onlineTodo.addListener('load', function () {
                console.log("I think we are online");
                FMS.stores.offlineTodo.proxy.clear();
                FMS.stores.onlineTodo.each(function (record) {                         
                      FMS.stores.offlineTodo.add(record.data)[0];
                });
                FMS.stores.offlineTodo.sync();
                FMS.stores.offlineTodo.load();
                flagoffline = 0;
            });
            
            if(flagoffline == 0){
                FMS.stores.onlineTodo.load();
            }
            else{
                FMS.stores.offlineTodo.load();
            }
    
    
        },

    HELP !!!!!

  2. First load the offline Store and if there is no data in there you should load the onlineStore.
    Here are some hints:

    Code:
    FMS.stores.offlineTodo = new Ext.data.Store({    model : 'ToDoMod',    proxy : {        type : 'localstorage',        id : 'fmsofflinetodo'    },    autoLoad: false});
    Code:
    // After load of onlineTodo
    if(
    FMS.stores.onlineTodo.data.length <= 0) { FMS.stores.offlineTodo.load();
    }

  3. #2
    Sencha Premium Member
    Join Date
    Jan 2012
    Posts
    39
    Vote Rating
    0
    Answers
    1
    gilles86 is on a distinguished road

      0  

    Default


    First load the offline Store and if there is no data in there you should load the onlineStore.
    Here are some hints:

    Code:
    FMS.stores.offlineTodo = new Ext.data.Store({    model : 'ToDoMod',    proxy : {        type : 'localstorage',        id : 'fmsofflinetodo'    },    autoLoad: false});
    Code:
    // After load of onlineTodo
    if(
    FMS.stores.onlineTodo.data.length <= 0) { FMS.stores.offlineTodo.load();
    }

Thread Participants: 1

Tags for this Thread