Answer the question
In order to leave comments, you need to log in
How to display other information about the product using id?
Hello! Guys, I ask for help with understanding on the following question!
I'm making a backend with mongoDB.
It is necessary to do:
1) Display a list of goods
2) When clicking on a product, go to the product page
As I see the solution to the first question (I omit the details, I speak abstractly)
On the first question! There is a request via fetch
fetch('http://localhost:3300/api/v5/products')
.then((response) => {
return response.json();
})
.then((data) => {
listOfPoduct(data);
});
function listOfPoduct ({ description, id, image, name, price }) {
const card = document.createElement('div');
card.insertAdjacentHTML('beforeend', `
<img src=${image} alt=${name} class="card-image"/>
<div class="card-text">
<div class="card-heading">
<h3 class="card-title card-title-reg">${name}</h3>
</div>
<div class="card-info">
<p class="ingredients">${description}</p>
</div>
<div class="card-buttons">
<a рука=”#” class=”addToProductPage”>переход на страницу товара</a>
<strong class="card-price card-price-bold">${price} ₽</strong>
</div>
</div>
`);
}
{
"id":"2121",
"name":"Sup merzi",
"count":"50g",
"type":"[vegan, '']",
"text":"Lorem impus",
"ingrediente":"Lorem impus...",
"valabil":"2121",
"pret":"50",
},
Answer the question
In order to leave comments, you need to log in
During the formation of the list of goods, set them the id of the goods, in the attribute of the same name, you can, you can in the date attribute, here it is more convenient. When clicking on a list element, read the given id and send a get request to the back specifying the product id or post request in the url, then you can simply write it in the body. On the back, process the id and send the required document from the database to the front.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question