Reputation: 1606
I have a view which gous like 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 is that
if(Ext.getStore('Userrights').findExact("name","admin_panel_access") !== -1)
Is not yet filled on the time when the part of code runs for:
hidden: !me.adminPanelEnabled
initComponent
function Kicks in?
Upvotes: 1
Views: 5441
Reputation: 1606
Ok thank you @seba for the idea i created in the consructor
applicationName.getApplication().on('allStoresLoaded', function() {
console.log(Ext.getStore('Userrights').findExact("name", "admin_panel_access"))
});
And it works now :D
Upvotes: 0
Reputation: 974
You should use callbacks when working with stores (generally when doing ajax calls). In your case your views should either be created when the store finished loading (use the load
event and let the callback create your view) or create a adminPanelEnabled()
method that get called by the load
event of the store.
Both variants have one thing in common, they get executed when the store finished loading.
In addition: if you just need this once you can register the event as sort of singleton
store.on('load', function(/*see api for ful arg list*/) {}, scope, { single:true })
Upvotes: 2