1. #1
    Sencha User
    Join Date
    Jul 2012
    Posts
    7
    Vote Rating
    1
    Roman_S is on a distinguished road

      0  

    Default Answered: Waiting for until Store is loaded not work

    Answered: Waiting for until Store is loaded not work


    Hi,

    i have a problem with loading my config store before my appication start.

    Code:
    var configStore = Ext.getStore("configStore");
    
    try{
    
        console.log("before load configStore");
        
        configStore.on('load', function(){
           
            console.log("load configStore");
            var data = this.getAt(0).getData();
            
            console.log("version: " + data.logo);
            Ext.ComponentQuery.query("#versionLabel")[0].setText(data.version);
        });
    
    }catch(err){
        console.log(err);
    }
    normal output:

    Code:
    before load configStore
    load configStore
    version: v1.0
    
    but often only this and the vesion field stay empty:

    Code:
    before load configStore
    

  2. the problem seems to be that the listener is not added to the store when the store is being loaded the first time (on autoLoad: true). To fix this, you can use the listeners config and directly add the listener in the store.

    Code:
    store = new Ext.data.Store({
      autoLoad: true,
      listeners:
      {
        load: function()
        {
            console.log("store loaded");
        }
      }
    });

  3. #2
    Ext JS Premium Member tvanzoelen's Avatar
    Join Date
    Apr 2008
    Location
    Groningen - Netherlands
    Posts
    1,114
    Answers
    83
    Vote Rating
    30
    tvanzoelen has a spectacular aura about tvanzoelen has a spectacular aura about tvanzoelen has a spectacular aura about

      0  

    Default


    Strange but earlier in previous versions it did matter if the number of parameters were correct

    Code:
    configStore.on('load', function(store, records, successful, eOpts ){
           
            console.log("load configStore");
            var data =  records;
            
            if(successful && store.getCount() > 0){   
               console.log("version: " + data[0].get('logo');
               Ext.ComponentQuery.query("#versionLabel")[0].setText(data[0].get('version'));
            }
            else{
                  console.log("no records");
             }
    
        });

  4. #3
    Sencha - Community Support Team sword-it's Avatar
    Join Date
    May 2012
    Location
    Istanbul
    Posts
    1,333
    Answers
    124
    Vote Rating
    85
    sword-it is a jewel in the rough sword-it is a jewel in the rough sword-it is a jewel in the rough sword-it is a jewel in the rough

      0  

    Default


    Hi Roman_s,

    Put a debugger after the getStore('configStore') and check configStore have your store reference.
    sword-it.com, Sencha Developer House in Turkey - Istanbul University Technopark Suite 204.

  5. #4
    Sencha User
    Join Date
    Jul 2012
    Posts
    7
    Vote Rating
    1
    Roman_S is on a distinguished road

      0  

    Default


    Quote Originally Posted by sword-it View Post
    Hi Roman_s,

    Put a debugger after the getStore('configStore') and check configStore have your store reference.
    Yes, the configStore has a reference.

    Now I have disabled the autoload property of the store and it seems to work

    Code:
    var configStore = Ext.getStore("configStore");
    configStore.load();
    
    configStore.on('load', function(store, records, successful, eOpts){
        
        console.log("load configStore");
        var data = records;
        
        if(successful && store.getCount() > 0){   
            Ext.ComponentQuery.query("#versionLabel")[0].setText(data[0].get('version'));
        }
        else{
            console.log("configstore records could not be loaded");
        }
    
    });

  6. #5
    Touch Premium Member
    Join Date
    Jun 2011
    Posts
    1,084
    Answers
    112
    Vote Rating
    95
    Farish is a glorious beacon of light Farish is a glorious beacon of light Farish is a glorious beacon of light Farish is a glorious beacon of light Farish is a glorious beacon of light

      0  

    Default


    the problem seems to be that the listener is not added to the store when the store is being loaded the first time (on autoLoad: true). To fix this, you can use the listeners config and directly add the listener in the store.

    Code:
    store = new Ext.data.Store({
      autoLoad: true,
      listeners:
      {
        load: function()
        {
            console.log("store loaded");
        }
      }
    });

  7. #6
    Sencha User
    Join Date
    Jul 2012
    Posts
    7
    Vote Rating
    1
    Roman_S is on a distinguished road

      0  

    Default


    Code:
    store = new Ext.data.Store({   
       autoLoad: true,   
       listeners:   {     
          load: function()     {         
             console.log("store loaded");     
          }   
       } 
    });
    Thanks, this solution works too.

  8. #7
    Sencha Premium Member dawesi's Avatar
    Join Date
    Mar 2007
    Location
    Melbourne, Australia (aka GMT+10)
    Posts
    1,083
    Answers
    24
    Vote Rating
    44
    dawesi has a spectacular aura about dawesi has a spectacular aura about

      0  

    Default


    also good to note that listeners should be in your controllers using best practice ExtJS 4.x
    Teahouse Training Company
    Official Certified Sencha Trainer

    Australia / New Zealand / Singapore / Hong Kong & APAC



    SenchaWorld.com - Sencha webinars, videos, etc
    SenchaForge.org - (coming soon)
    TeahouseHQ.com - Sencha ecosystem training portal

    Code Validation : JSLint | JSONLint | JSONPLint