I have a view that has many containers in ExtJs. Consider the items of the view are something like the following.
initComponent : function(){
this.items = [{
xtype : 'button',
text : 'menu1',
itemId : 'btnMenu1'
},{
xtype : 'button',
text : 'menu2',
itemId : 'btnMenu2'
},{
xtype : 'button',
text : 'menu3',
itemId : 'btnMenu3'
},{
xtype : 'container',
itemId : 'report1',
items : [{
xtype : 'button',
title : 'clickme 1'
}]
},{
xtype : 'container',
itemId : 'report2',
items : [{
xtype : 'button',
title : 'clickme 2'
}]
},{
xtype : 'container',
itemId : 'report3',
items : [{
xtype : 'button',
title : 'clickme 3'
}]
}]
this.callParent();
}
Then in mycontroller I want to hide and show the containers according to the button I click. In the controller I have the refs and selectors for these containers,
refs : [{
/***all containers**/
ref : 'ref....',
selector : 'selector....'
}],
And then when I click a button I execute a function
init: function() {
this.control({
'selector' : {
click : this.menu1
},
'selector' : {
click : this.menu2
},
'selector' : {
click : this.menu3
}
});
},
Then in each function I just show/hide containers (same logic for all)
menu1 : function(){
this.getConatiner1().show();
this.getContainer2().hide();
this.getContainer3().hide();
},
Everything works fine but the problem is how to handle this behavior if I have 100 conatiners (for any reason, does not matter).
How can I show/hide containers dynamically without repeating too many lines of code for manually hide/show containers?
I have tried to assign all selectors to an array something like
var selectors = ['getContainer1','getContainer2',...]
and then just using a for loop to hide all of them and just show the correct one.
for(allselectors){
eval('selector.hide()');
}
selectedContainer.show();
Something like this seems to work, but I prefer to avoid eval. Any suggestions for this kind of logic?
this.items =in the constructor, not initComponent. - incutonezinitComponent. Seems interesting to research why this should be done in constructor. Maybe in another post - dev