-
Notifications
You must be signed in to change notification settings - Fork 19
Expand file tree
/
Copy pathscript3.js
More file actions
65 lines (49 loc) · 1.73 KB
/
script3.js
File metadata and controls
65 lines (49 loc) · 1.73 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
const catecont = document.querySelector('.categories');
const itemscont = document.querySelector('.items');
async function fetching() {
const [categoryres, itemres] = await Promise.all([
fetch("http://43.205.110.71:8000/categories"),
fetch("http://43.205.110.71:8000/items")
]);
const categories = await categoryres.json() ;
const items = await itemres.json();
function showitems(items) {
itemscont.innerHTML = "";
items.forEach((item) =>{
const itemcont = document.createElement("div");
itemcont.innerHTML =
`<img src="https://picsum.photos/seed/${item.id}/200/200">
<h3>${item.name}</h3>
<h4>price: ${item.price}</h4>`;
itemcont.className = "item";
itemscont.append(itemcont);
console.log("hello");
});
}
showitems(items);
categories.forEach (category => {
const btn1 = document.createElement("button");
btn1.innerText = category.category ;
btn1.className = "btnclass";
catecont.append(btn1);
const itemcate = items.filter(item => item.category === category.category);
btn1.onclick = () => {
showitems(itemcate);
};
})
const tab = document.getElementById("tab");
const searchbut = document.getElementById("searchbut");
searchbut.onclick = () => {
const itemcate = items.filter(item => item.category === tab.value);
showitems(itemcate);
console.log(tab.value);
}
const tab2 = document.getElementById("tab2");
const searchbut2 = document.getElementById("searchbut2");
searchbut2.onclick = () => {
const itemtag = items.filter(item => item.tags.includes(tab2.value));
showitems(itemtag);
console.log(tab2.value);
}
}
fetching();