I am a noob to the extjs 4 MVC design. I have the following code.
onLaunch: function() {
console.log("Launched Business Unit Controller");
var businessunitsStore = this.getStore('Businessunits');
businessunitsStore.load(function(records){
var comp = Ext.getCmp('business_form');
for(var i=0;i<records.length;i++){
bu = records[i].data;
console.log(bu);
comp.add({
xtype:'button',
cls:'x-button',
width:90,
autoScroll:false,
height:60,
text:bu.businessunit_name,
enableToggle:true,
listeners:{
click: function(){
var pnl = Ext.getCmp('active-units-form');
pnl.add({
xtype:'label',
text:this.text,
})
}
}
}) //comp.add
} //for ...
});
}
As you can see i am adding a button on store load, and each button has further events down the line. The problem is i want to handle the sub events like the click events of the buttons down the chain outside the onLaunch as a separate method. But it seems like i cannot get out of this loop and all events are to be written as a chain. But it seems so wrong and with increasing amount of listeners, code gets messy. So is there a way that i can switch back and forth between controller methods and internals