Search code examples
model-view-controllersencha-touchdatastore

Sencha Touch dynamically use of stores with mvc?


so here is the problem, I use MVC and I have several stores that I declared on app.js.

But now I need to do a login validation, and only load the stores after I get the response from the server, but if leave the declaration in app.js when the app loads it automatically loads all the stores.

Here is what my app is going needs to do:

LoginView make the validation, if validation is successful it changes the view to ListView, this view has a list that loads data from a store and this view can create other views with other lists.

I tried to require the stores in the ListView, but it throws errors cannot call method getCount of null.

What can I do to make it work. Thanks for the help.

Here is some code:

Ext.define("App.view.Listview", {
extend: 'Ext.Container',
xtype: 'listview',

requires: ['App.view.Listviewdetails',
    'App.view.Filtros.FiltroJanelaPrincipal.Janelafiltrotiempoview',
    'App.view.Menuview',
    'App.view.Resultadopesquisaview',
    'App.view.Pesquisaview',
    'App.view.Maisinfousuarioview',
    'Ext.Label',
    'Ext.field.Search',
    'App.store.Tiempos',
    'App.store.Empresas',
    'App.store.Produtos',
    'App.store.Usuarios',
    'App.store.FiltrosEvento',
    'App.store.Historicos',
    'App.store.Pesquisas'
],

config: {
    id: 'listView',
    layout: 'card',
    items: {
        layout: 'vbox',
        id: 'listaEventos',
        items: [
            {
                xtype: 'list',
                id: 'listaTiempos',
                flex: 6,
                emptyText: 'Empty',
                store: 'Tiempos',
                itemTpl: '{dataTermino} {descricaoPrevia}'
            }
        ]
    }

and one of the stores:

Ext.define("App.store.Tiempos",{
extend: 'Ext.data.Store',

config: {
    model: 'App.model.Tiempo',
    autoLoad: true,
    proxy: 'searchProxy'
}

});


Solution

  • You can add the stores in require in the respective view classes. It is not compulsory to add in app.js. So after login when the view will be instantiated the store will be loaded automatically.