JSFiddle - React, Tailwind, and code Playground
by molecule
HTML
<input type="button" value="click me" id="btn" />
JavaScript
$('#btn').click(function() {
$('<div id="autoGeneratedDialog">This is a dialog</div>').appendTo('body');
var JSON = [{
label: 'btn 1',
ajax: 'url'},
{
label: 'btn 2',
ajax: 'url'}];
var aButtons = {};
aButtons['Abandonner'] = function() {
$(this).dialog("close");
};
for (var x = 0; x < JSON.length; x++) {
aButtons[JSON[x].label] = (function() {
var i = x;
return function() {
alert(i);
alert(JSON[i].label);
}
})();
}
$('#autoGeneratedDialog').dialog({
'title': 'title',
'width': '400px',
'height': '400px',
'max-height': '900px',
modal: true,
buttons: aButtons,
close: function() {
$('#autoGeneratedDialog').remove();
}
});
});