PDA

View Full Version : Generate button dynamically with function



slsb02
13 Jan 2015, 12:15 AM
Hello,

I create dynamic buttons. This should run with a parameter in a function click. The parameter is an ID. The problem that arises when all buttons the same parameters and it is always last. I hope you have an idea !?

What is the best way to do this?



for (i=0; i<dataLength; i++) {
stationID = store.data.items[i].get('workstation_id');

items: [{
xtype:'button', id: 'start-button-'+stationID, text: "Start", cls: 'worsp-clock-button',
handler: function() { doTHIS(stationID); }
}]
}


"id" has the correct stationID but not "doTHIS()"...

Jad
13 Jan 2015, 5:59 AM
hi, try this



for (i=0; i<dataLength; i++) { stationID = store.data.items[i].get('workstation_id'); items: [{ xtype:'button', stationID: stationID, id: 'start-button-'+stationID, text: "Start", cls: 'worsp-clock-button', handler: function (button) { doTHIS(button.stationID); } }]}

slsb02
13 Jan 2015, 7:47 AM
perfect, thank you!!!