javascript - Extjs Load store before the view -


i have view gous this:

ext.define('webedi.view.zones.menu', {     store: 'partnersettings',     extend: 'ext.panel.panel',             .             .             .             .     adminpanelenabled: false,     initcomponent: function() {         var me = this;  console.log(ext.getstore('userrights').findexact("name","admin_panel_access"));            if(ext.getstore('userrights').findexact("name","admin_panel_access") !== -1) me.adminpanelenabled = true; //        if(ext.getstore('partnersettings').getat(0).get('purchasingorganisation').enabled ) me.purchasingorganisationenabled = true;         this.items = [                     .                     .                     .                     .                      {                         id: 'adminpanel',                         itemid: 'adminpanel',                         xtype: 'button',                         text: translation.zonesmenuadminpanel,                         action: 'adminpanel',                         margin: '3 3 0 3',                         hidden: !me.adminpanelenabled                     }                 ]             }         ];          this.callparent();     } }); 

the problem

 if(ext.getstore('userrights').findexact("name","admin_panel_access") !== -1) 

is not yet filled on time when part of code runs for:

 hidden: !me.adminpanelenabled 

initcomponent function kicks in?

you should use callbacks when working stores (generally when doing ajax calls). in case views should either created when store finished loading (use load event , let callback create view) or create adminpanelenabled() method called load event of store.

both variants have 1 thing in common, executed when store finished loading.

in addition: if need once can register event sort of singleton

store.on('load', function(/*see api ful arg list*/) {}, scope, { single:true }) 

Comments

Popular posts from this blog

java.util.scanner - How to read and add only numbers to array from a text file -

rewrite - Trouble with Wordpress multiple custom querystrings -

php - Accessing static methods using newly created $obj or using class Name -