Results 1 to 4 of 4

Thread: Switch between Stores

  1. #1

    Default Answered: Switch between Stores

    Hi All,

    I want to switch between a online and offline store. When the application start it need to use the local store. But when the user refresh (PullRefresh plugin) the application needs to refresh the online store.

    VIEWS:

    Code:
    Ext.define('myapp.view.task.Nav', {
    
    
        extend: 'Ext.NavigationView',
        xtype: 'taskContainer',
    
    
        config: {
    
    
            title: 'Tasks',
            iconCls: 'user',
            autoDestroy: false,
    
    
            items: [
                {
                    xtype: 'tasks',
                    store: 'OnlineTaskStore',
                    grouped: true,
                    pinHeaders: false
                }
            ]
        }
    
    
    })
    
    Ext.define('myapp.view.task.List', {
    
    
        extend: 'Ext.List',
        xtype: 'tasks',
        id: 'tasklist',
    
    
        config: {
            title: 'Tasks',
            fullscreen: true,
    
    
            plugins: [
                { xclass: 'Ext.plugin.ListPaging' },
                { xclass: 'Ext.plugin.PullRefresh'}
            ],
    
    
            itemTpl: [
                '<div class="session"><div class="firstName">{name}</div><div class="room">{projectid}</div></div>'
            ]
    
    
        },
    
    
        initialize: function() {
            this.callParent();
        }
    })
    STORES:

    Code:
    Ext.define('myapp.store.OnlineTaskStore', {
        extend: 'Ext.data.Store',
    
    
        config: {
            model: "myapp.model.Task",
    
    
            sorters: 'name',
    
    
            grouper: {
                groupFn: function(record) {
                    return record.get('name')[0];
                }
            },
    
    
            proxy: {
                type: 'ajax',
                url: 'data/data2.json',
                method: 'post',
                extraParams: {
                    apikey: 'apikay'
                },
                reader: {
                    type: 'json',
                    rootProperty: 'items'
                },
                timeout: 2000,
                listeners: {
                    onChange: function(){
                        console.log('Load')
                    },
                    exception:function () {
                        console.log("I think we are offline");
                    }
                }
            },
            listeners: {
                load: function() {
                    console.log('Saved to local');
                    this.each(function(record){
                        this.save();
                    })
                }
            }
        }
    });
    
    Ext.define('myapp.store.OfflineTaskStore', {
        extend: 'Ext.data.Store',
        config: {
            model: 'myapp.model.Task',
            sorters: 'name',
    
    
            grouper: {
                groupFn: function(record) {
                    return record.get('name')[0];
                }
            }
        }
    });
    So when the application startsup it needs to get the local data (if not empty) & then set the online store as the active store. I tried something like bindStore but it's not working.

    Does anyone have a suggestion / solution?

  2. Check out the source code from some of Sencha's examples...

    You have to set up a ref for your list in your controller. Then:

    Code:
    var myList = this.getMyList();
    myList.setStore(myStore);

  3. #2
    Sencha User
    Join Date
    Apr 2011
    Posts
    40
    Answers
    2

    Default

    have you tried setStore()?

  4. #3

    Default

    Howdoes that work?If Idothe myapp.view.task.List.setStore() in my controller, i get methodnot found.But if I doconsole.log(myapp.view.task.List),It outputs the List object.

  5. #4
    Sencha User
    Join Date
    Apr 2011
    Posts
    40
    Answers
    2

    Default

    Check out the source code from some of Sencha's examples...

    You have to set up a ref for your list in your controller. Then:

    Code:
    var myList = this.getMyList();
    myList.setStore(myStore);

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •