HTML
Код: Выделить всё
#[date]
#[sis]:#[dia]
#[freq]
#[id]
Код: Выделить всё
const fillTable = (objs) => {
objs.forEach(obj => {
let tbody = document.querySelector(`tbody`)
let html = document.querySelector(`template`).innerHTML
let string = Object.entries(obj).reduce((str, key) => {
return str.replace(`#[${key[0]}]`, key[1])
}, html)
// HTMLElement.appendChild(node)
// HTMLElement.append(string)
tbody.innerHTML += string
})
}
addEventListener(`DOMContentLoaded`, async () => {
let resp = await fetch(`https://my-api-g8he.onrender.com/medidas`)
let data = await resp.json()
fillTable(data.data)
})
Код: Выделить всё
HTMLElement.appendChild(node)
Код: Выделить всё
HTMLElement.append(string)
Код: Выделить всё
HTMLElement.innerHTML += string
Попробуйте эту скрипту
Код: Выделить всё
function fillTable(objects) {
let tbody = document.querySelector('tbody');
let html = document.querySelector('template').innerHTML;
let parser = new DOMParser();
objects.forEach(object => {
let string = Object.entries(object).reduce((str, key) => {
return str.replace(`#[${key[0]}]`, key[1]);
}, html);
console.log(string);
let node = parser.parseFromString(string, 'text/html').body.firstChild
console.log(node);
tbody.appendChild(node);
});
}
addEventListener('DOMContentLoaded', async () => {
let response = await fetch('https://my-api-g8he.onrender.com/medidas');
let json = await response.json();
let objects = json.data;
fillTable(objects);
});Код: Выделить всё
* {
margin: 0;
padding: 0;
box-sizing: border-box;
font-family: sans-serif;
}
body {
display: flex;
flex-direction: column;
align-items: center;
}
table {
width: 100%;
max-width: 400px;
}
table th {
text-align: left;
background-color: #000;
color: #fff;
}
table tr:nth-child(even) {
background-color: #ccc;
}Код: Выделить всё
data
pressão
frequencia
#[date]
#[sis]:#[dia]
#[freq]
#[id]
Подробнее здесь: https://stackoverflow.com/questions/794 ... -html-tags
Мобильная версия