-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
34 lines (28 loc) · 814 Bytes
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
var main = (function () {
function stringToNode(_string) {
var template = document.createElement('template');
template.innerHTML = _string;
return template.content.firstChild;
}
function renderItem (item) {
return stringToNode(
'<div>' +
'<div class="item-name">'+ item.name +'</div>' +
'<button type="button" class="add-menu-item" data-id="'+ item.id +'">add</button>' +
'<button type="button" class="remove-menu-item" data-id="'+ item.id +'">remove</button>' +
'</div>'
)
}
function clearItems () {
dom.menuItems().innerHTML = '';
}
return {
render: function () {
clearItems();
data.menuItems.map(function (item) {
dom.menuItems().appendChild(renderItem(item));
})
}
}
})();
main.render();