Enviado em 25/06/2020 - 10:12h
Pessoal, bom dia!! Preciso de ajuda com um javascript.
$(document).ready(function(){
$("#button-buscar-licencas").click(function(){
var urlapi = 'http';
var url=urlapi;
var xhttp = new XMLHttpRequest();
xhttp.open("GET", url, false);
xhttp.send();
var obj = JSON.parse(xhttp.responseText);
var data_map = new Map();
var index = 0;
for (i = 0; i < obj.length; i++) {
if(data_map.has(obj[i].hostGroup.name)) {
data_map.set(obj[i].hostGroup.name, data_map.get(obj[i].hostGroup.name) + +obj[i].consumedHostUnits);
}
else {
data_map.set(obj[i].hostGroup.name, +obj[i].consumedHostUnits);
}
}
const objConverted = Object.fromEntries(data_map);
var myJSON = JSON.stringify(objConverted);
data_map.forEach(montaTabelaLicencas);
event.preventDefault();
});
});
function montaTabelaLicencas(hostgroup, licenca) {
var newRow = $('<tr class="licenca">');
var cols = "";
cols += '<td class="hostgroup-info" id="texto-hostgroup">' + licenca + '</td>';
cols += '<td class="licenca-info" id="text-licenca">' + hostgroup + '</td>';
cols += '<td class="actions">';
cols += '<button type="button" class="btn fas fa-copy" id="button-copy" disabled title="Em Breve"></button>';
newRow.append(cols);
$("#table-licencas").append(newRow);
return false;
};