I am developing a web application, basically what I have to do is create components of a form based on the information I collect from a database.
var _populate = function (idparametro) {
jQuery.ajax({
type: "GET",
async: false,
url: pathservicehost + '/dominios/' + idparametro,
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (data, status, jqXHR) {
console.log('Dominios Ok...');
return data;
},
error: function (jqXHR, status) {
alert('Error (Obtener Dominios)');
}
});
};
var _draw = function (callback) {
idparametro = 100;
data = callback(idparametro);
defecto = -1;
for (var i = 0; i < data.length; i++)
if (data[i].Defecto == 1) defecto = i;
$('#cbxparam').kendoComboBox({
animation: false,
dataTextField: "Descripcion",
dataValueField: "Descripcion",
dataSource: data,
filter: "contains",
suggest: true,
index: defecto
});
};
The function _populate what it does is bring the data with which for example a combobox is populated or the values that a group of radiobuttons must have and the function _draw is responsible for drawing the widget (with the data that corresponds to it ). The problem I have is that I need to find out how the _draw function waits for _populate to finish consuming the service and the data is returned before continuing to execute the following lines of code (for loop).
I hope someone can give me my regards.