import { getEmployees } from "./apiService.js"; const doc = { empsBody: document.querySelector('#empsBody') } const state = { empList: [] } window.addEventListener('load', () => { init(); }); function init() { getEmps(); } async function getEmps() { state.empList = await getEmployees(); renderTable() } function renderTable() { state.empList.forEach(emp => { let tr = document.createElement('tr'); tr.innerHTML =` ${emp.id} ${emp.name} ${emp.city} ${emp.salary} `; const editBtn = tr.querySelector('button:nth-child(1)'); editBtn.addEventListener('click', () => updateEmployee(editBtn)); const delBtn = tr.querySelector('button:nth-child(2)'); delBtn.addEventListener('click', () => deleteEmployee(emp.id)); doc.empsBody.appendChild(tr); }); } function updateEmployee(source) { console.log(source.dataset.city) } function deleteEmployee(id) { console.log(id) }