I have a pretty simple code that checks if the items in an array are contained in another. If they are, I push into the itens array an input checked checkbox, if they are not, I push a regular unchecked checkbox to the array. Check it out:
$.ajax({
url: '${pageContext.request.contextPath}/filial/select.json',
method: 'GET'
}).done(function(json) {
var itens=[];
var filiaisSelecionadas = ${filiais};
for (var i = 0; i < json.length; i++) {
if(filiaisSelecionadas.includes(json[i])){
itens.push('<input id= "idFilial'+json[i][0]+'" type = checkbox class=checkbox1 name = filiaisId value="'+json[i][0]+'" checked>' +json[i][1]+"-"+ json[i][2] + '</input></br>');
}
else{
itens.push('<input id= "idFilial'+json[i][0]+'" type = checkbox class=checkbox1 name = filiaisId value="'+json[i][0]+'">' +json[i][1]+"-"+ json[i][2] + '</input></br>');
}
}
$('#idFilial').html($("<tbody/>", {html:itens}));
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>But for some reason the code inside the if(filiaisSelecionadas.includes(json[i])) just doesn't execute. The treatment works just fine. If the item isn't in the array it pushes the unchecked checkbox. However if the item IS in the array, it just doesn't execute? I would understand if it always executed the else statement, but not executing neither???? This confuses de b'jesus out of me...
Aucun commentaire:
Enregistrer un commentaire