Results 1 to 7 of 7

Thread: How to load a store from the controller?

  1. #1
    Sencha User
    Join Date
    Feb 2013
    Posts
    11
    Vote Rating
    0
      0  

    Default How to load a store from the controller?

    I have a store that works well when I have put "autoLoad: true". Now I need to modify it to load if the login is correct.

    My Store:

    Code:
    Ext.define('plataformatechnosite.store.Feeds', {
        extend: 'Ext.data.Store',
        config: {
            model: 'plataformatechnosite.model.Feed',
            //autoLoad: true,
            storeId: 'feedsStore',
            proxy: {
                type: 'jsonp',
                url:'http://xxxx.yyyy',
                callbackKey: 'callback',
                reader: {
                    type: 'json',
                    rootProperty: 'listaMedios'
                },
                callback: function(data) { 
                    console.log("callback" + data);
                },
                afterRequest: function(req, res) {
                    console.log("Ahoy!", req.operation.response);    
                }
            },
            
            timeout: 3000, //milliseconds
            listeners: {
                load: function(store, records, success) {
                    console.log("Load: success " + success);     
                },
                exception:function(proxy, response){
                     console.error(response.responseText);
                }
            }
        }
    });

    My Controller:

    Code:
    Ext.define('plataformatechnosite.controller.Login', {
    extend: 'Ext.app.Controller',
    autoDestory:false,
    config: {
        refs: {
            loginButton: {
                selector: '#login',
                xtype: 'button'
            },
            username: {
                selector: '#user',
                xtype: 'textfield'
            },
            password: {
                selector: '#pass',
                xtype: 'passwordfield'
            },
            mainTabPanel: {
                selector: '#mainTabPanel',
                xtype: 'tabpanel',
                autoCreate: true
            }
        },
    
        control: {
            "loginButton": {
                tap: 'onLoginButtonTap'
            }
        }
    },
    
    onLoginButtonTap: function(button, e, options) {
        
        Ext.data.JsonP.request({
                url: 'http://xxxx.zzzzz',
                callbackKey: 'callback',
                timeout : 100000,
                params: {
                    usuario: this.getUsername().getValue(),
                    password: this.getPassword().getValue()
                },
                callback: function(data) { 
                    //console.log("callback" + data);
                },
                success: function(result, request) {
                   console.log("txt:"+result);
                   if(result == true){
                         //load Store,  WS Proxy
                         var cargarFeeds = Ext.getStore('feedsStore');
                         cargarFeeds.load();
                         
                         var feeds = Ext.create('plataformatechnosite.view.Feeds');
                         Ext.Viewport.add(feeds);
                         Ext.Viewport.setActiveItem(feeds);
                         
                   }else{
                       Ext.Msg.alert('Error', 'Los credenciales insertados no son correctos.', Ext.emptyFn);
                   }
                   
                },
                failure: function(response) {
                    console.log("failure");
                    Ext.Msg.alert('Error', 'Existen problemas de conexion con el servidor.', Ext.emptyFn);
    
                }
                
            });
    }
    });
    This does not work. The msg:
    Code:
    [WARN][plataformatechnosite.view.Feeds#applyStore] The specified Store cannot be found Console.js:35
    Load: success true
    For the messages seems to load the store but on screen I see nothing.
    ideas? thankyou!

  2. #2
    Sencha User
    Join Date
    Feb 2011
    Location
    Dsseldorf, Germany
    Posts
    594
    Answers
    35
    Vote Rating
    33
      0  

    Default

    Does your last two lines mean, that the success message of the store fires after you try to build the view?
    Loading is asynchrone so you might need to wait for the loading to finish.

  3. #3
    Sencha User bluehipy's Avatar
    Join Date
    Mar 2010
    Location
    Romania
    Posts
    623
    Answers
    67
    Vote Rating
    29
      0  

    Default

    PHP Code:
    if(result == true){

    var 
    store Ext.data.StoreManager.lookup('feedsStore');
    if(
    store) {
        
    store.load();
    }
    ...


    Latest thoughts on the subject: http://joy2share.com/senchatouch/

  4. #4
    Sencha User
    Join Date
    Feb 2013
    Posts
    11
    Vote Rating
    0
      0  

    Default

    Thanks for your answers!

    Kurt001 yes, the last two lines mean there is any response but does not wait to upload. How do I wait?

    bluehipy this solution does not work but thank you!




  5. #5
    Sencha Premium Member
    Join Date
    May 2011
    Posts
    71
    Answers
    5
    Vote Rating
    6
      0  

    Default

    Post the code for your view. It's possible there's something wrong with the way the store is specified in the view's configuration.

  6. #6
    Sencha User
    Join Date
    Feb 2013
    Posts
    11
    Vote Rating
    0
      0  

    Default

    fixed! the problem was in the view!

    config: {
    store: 'feedsStore',



    thank you!

  7. #7
    Sencha User bluehipy's Avatar
    Join Date
    Mar 2010
    Location
    Romania
    Posts
    623
    Answers
    67
    Vote Rating
    29
      0  

    Default

    You didn't post the code with the problem so we just suggested on what we saw

    Good luck!
    Latest thoughts on the subject: http://joy2share.com/senchatouch/

Tags for this Thread

Posting Permissions

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