Internet_Programmirovanie_N.../Lab2/js/bebra.js

32 lines
830 B
JavaScript
Raw Permalink Normal View History

const serverUrl = "http://localhost:8081";
const lst= document.querySelector("#time");
export async function getAllItemTime() {
const response = await fetch(`${serverUrl}/time`);
if (!response.ok) {
throw response.statusText;
}
return response.json();
}
function createOption( time){
const option = document.createElement("option");
option.textContent = time.timer;
//option.text = name;
//option.selected = isSelected;
lst.appendChild(option);
}
export default async function fillList(){
const data = await getAllItemTime();
lst.innerHTML ="";
// пустое значение
//lst.appendChild(createOption("выберите значение","", true));
data.forEach((time)=>{
// if(time.trim() !== ""){
createOption(time);
// }
})
}