const scene = { 'scena 1': () => { }, 'scena 2': () => { }, 'scena 3': () => { } } const gumbi = { 'kalibriraj': () => { console.log('kalibriram') sendAll('/ww/calibrate') } } const qs = s => document.querySelector(s) const qsa = s => document.querySelectorAll(s) const ce = e => document.createElement(e) window.addEventListener('DOMContentLoaded', () => { // Dodaj scene const sceneTD = qs('#scene') Object.keys(scene).forEach(ime => { const b = ce('button') b.innerHTML = ime b.onclick = () => { console.log('izbiram ', ime) scene[ime]() } sceneTD.append(b) }) // Dodaj gumbe const gumbiT = qs('#ctl') Object.keys(gumbi).forEach(ime => { const v = ce('tr') const ic = ce('td') ic.append(ime) v.append(ic) const g = ce('button') g.id = 'gumb_' + ime g.innerHTML = ' ' const gc = ce('td') gc.append(g) v.append(gc) g.onclick = () => { console.log('spreminjam', ime) gumbi[ime]() } gumbiT.append(v) }) })