I have the following idea that the moderator Sergio sent
var obj = [JSON]
var mydiv = document.getElementById("tabLista");
mydiv.innerHTML = "";
var ul = document.createElement("ul");
mydiv.appendChild(ul);
var escolhidas = [];
obj.forEach(function(obj) {
obj = obj.List;
var li = document.createElement("li");
ul.appendChild(li);
Object.keys(obj).forEach(function(chave) {
var div = document.createElement("div");
div.classList.add(chave);
div.textContent = obj[chave];
li.appendChild(div);
});
var checkbox = document.createElement("input");
checkbox.type = 'checkbox';
checkbox.addEventListener('change', function() {
this.closest('li').classList.toggle('selecionado', this.checked);
if (this.checked) escolhidas.push(obj);
else escolhidas = escolhidas.filter(function(el) {
return el != obj;
});
console.log(escolhidas);
});
li.appendChild(checkbox);
});
Only when I enter json that my server responds the script does not recognize the keys, it only prints
[object Object]
[object Object]
[object Object]
Json that my server responds
{
"api": "api",
"List": [{
"tipo": "1",
"data": "10/10/2017",
"Hora": "11:38",
"Size": "0",
"Nome": "Marcelo"
}, {
"tipo": "1",
"data": "10/10/2017",
"Hora": "11:38",
"Size": "0",
"Nome": "Pedro"
}, {
"tipo": "1",
"data": "10/10/2017",
"Hora": "11:38",
"Size": "0",
"Nome": "Lucas"
}],
"arq": "1",
"paste": "2"
}
Json From the original idea
var obj = [{
nome: 'a',
data: '13/09/2017'
},
{
nome: 'b',
data: '13/09/2017'
},
{
nome: 'c',
data: '13/09/2017'
},
{
nome: 'd',
data: '13/09/2017'
},
]
Obtained:)