-
Notifications
You must be signed in to change notification settings - Fork 2
/
listView.js
51 lines (43 loc) · 1.72 KB
/
listView.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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
import { elements } from './base';
export const renderItem = item => {
// Get the markup below .shopping__list class in ./index.html
/** Array Version */
// const markup = `
// <li class="shopping__item" data-itemid=${item.id}>
// <div class="shopping__count">
// <input type="number" value="${item.count}" step="${item.count}" class="shopping__count-value">
// <p>${item.unit}</p>
// </div>
// <p class="shopping__description">${item.ingredient}</p>
// <button class="shopping__delete btn-tiny">
// <svg>
// <use href="img/icons.svg#icon-circle-with-cross"></use>
// </svg>
// </button>
// </li>
// `;
/** Map Version */
const markup = `
<li class="shopping__item" data-itemid=${item.id}>
<div class="shopping__count">
<input type="number" value="${item.value.count}" step="${item.value.count}" class="shopping__count-value">
<p>${item.value.unit}</p>
</div>
<p class="shopping__description">${item.value.ingredient}</p>
<button class="shopping__delete btn-tiny">
<svg>
<use href="img/icons.svg#icon-circle-with-cross"></use>
</svg>
</button>
</li>
`;
elements.shopping.insertAdjacentHTML('beforeend', markup);
};
export const deleteItem = id => {
/** Array Version */
// const item = document.querySelector(`[data-itemid="${id}"]`);
// item.parentElement.removeChild(item);
/** Map Version */
const item = document.querySelector(`[data-itemid="${id}"]`);
item.parentElement.removeChild(item);
};