i have created six buttons dynamically using initialize function,also i have assigned different id’s to each buttons dynamically,I want to handle event for each button,When i click each of the different button i am getting alert message of sixth button id,How to handle particular button event. Thank you
Ext.define("DynamicButton.view.Main", {
extend: 'Ext.Panel',
initialize: function () {
var me = this;
me.names = ['Button1', 'Button2', 'Button3', 'Button4', 'Button5', 'Button6'];
var toolBar = Ext.create('Ext.Toolbar', {
docked: "bottom"
});
this.add(toolBar);
for (var i = 0; i < me.names.length; i++) {
var name = me.names[i];
var button = Ext.create('Ext.Button', {
id: 'Btn' + name,
html: name,
handler: function() {
alert(button.id);
},
scope: this
});
toolBar.add(button);
}
},
config: {
}
});
You can also access the button through the params of the handler function :
I might be useful if you want to change the scope.
Hope this helps