-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathL5T4.js
More file actions
82 lines (79 loc) · 2.14 KB
/
L5T4.js
File metadata and controls
82 lines (79 loc) · 2.14 KB
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
"use strict";
let catalogItem = {
render(item) {
return `<div class="basket_list">
<div>Наименование: <b>${item.name}</b></div>
<tr><td>Количество: <b>${item.quantity}</b></td>
<td>Цена за шт.: <b>${item.price}</b></td>
</div><br/>`;
}
}
let catalog = {
catalogID: null,
catalogList: null,
catalogItem,
category: ['Выпечка', 'Алкоголь', 'Товары для дома'],
products: [
{
id: 1,
category: 1,
manufacturer: 'Фили Бэйкер',
name: 'торт',
price: 420,
quantity: 1
},
{
id: 2,
category: 2,
manufacturer: 'Koor',
name: 'вино',
price: 750,
quantity: 3
},
{
id: 3,
category: 3,
manufacturer: 'Да будет свет!',
name: 'свечи',
price: 59,
quantity: 5
},
{
id: 4,
category: 2,
manufacturer: 'Абруа',
name: 'шампанское',
price: 550,
quantity: 2
},
{
id: 5,
category: 2,
manufacturer: 'Jeck',
name: 'виски',
price: 1750,
quantity: 7
},
{
id: 6,
category: 2,
manufacturer: 'Амарето',
name: 'ликер',
price: 950,
quantity: 2
},
],
init(catalogID) {
this.catalogID = catalogID;
this.catalogList = document.querySelector('.catalog');
this.render(this.products);
},
render() {
this.catalogList.insertAdjacentHTML('beforeEnd', `<h1>${this.category[this.catalogID - 1]}</h1>`);
this.products.forEach(item => {
if (item.category == this.catalogID)
this.catalogList.insertAdjacentHTML('beforeEnd', this.catalogItem.render(item));
});
},
}
catalog.init(2);