nvm list available
nvm install 18.18.0
nvm use 18.18.0
node -v
// v18.18.0
function loadSelectOptions(url, selectElement, keyVal, keyText) {
return fetch(url)
.then(response => {
if (!response.ok) {
throw new Error('Ошибка загрузки данных');
}
return response.json();
})
.then(data => {
data.forEach(item => {
const option = createOption(item[keyVal], item[keyText]);
selectElement.appendChild(option);
});
})
.catch(error => {
console.error(error);
});
}
loadSelectOptions('http://:3000/type_work', selectElement, 'type_work', 'type_work');
loadSelectOptions('http://:3000/printerCB', selectElement, 'printer_id', 'printer');
loadSelectOptions('http://:3000/printer_material?printer_id=2', selectElement, 'printer_id', 'material');
loadSelectOptions('http://:3000/performers', selectElement, 'performer_id', 'performer');
loadSelectOptions('http://:3000/printer_format?printer_id=2', selectElement, 'printer_id', 'format');