-
Notifications
You must be signed in to change notification settings - Fork 0
/
pesquisa.js
52 lines (33 loc) · 1.42 KB
/
pesquisa.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
51
52
const userCardTemplate = document.querySelector("[data-user-template]")
const userCardContainer = document.querySelector("[data-user-cards-container]")
const searchInput = document.querySelector("[data-search]")
let products = []
searchInput.addEventListener("input", e => {
const value = e.target.value.toLowerCase()
products.forEach(products => {
const isVisible =
products.title.toLowerCase().includes(value)
products.element.classList.toggle("hide", !isVisible)
})
})
fetch("./products.json")
.then(res => res.json())
.then(data => {
products = data.map(products => {
const card = userCardTemplate.content.cloneNode(true).children[0]
const header = card.querySelector("[data-header]")
const body = card.querySelector("[data-body]")
const price = card.querySelector("[data-price]")
const local = card.querySelector("[data-local]")
const imgtag = card.querySelector("[data-image]");
console.log(imgtag)
imgtag.src = products.filename
header.textContent = products.title
body.textContent = products.type
price.textContent = products.price
local.textContent= products.description
userCardContainer.append(card)
return { title: products.title, type: products.type, price: products.price,local:products.description, element: card ,imgtag:products.filename
}
})
})