Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

97
Views
¿Es posible enviar múltiples datos en una sola vista en Node JS?

Estoy tratando de pasar varios datos a una vista. Puedo enviarle los productos, pero también me gustaría enviar las categorías. Quiero enviarlos por separado y no con una unión. Me han aconsejado que lo ponga después del "entonces", pero no sé cómo hacerlo.

 router.get('/', function (req, res) { models.produit.findAll( { include: [ { model: models.image, as: "images" }, { model: models.promotionproduit, as: "promotionproduits", include:[{model: models.promotion, as: "Promotion"}] } ]}) .then(data => { res.render('home', { data: data }); }).catch(err => console.log(err)); });
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Claro, use async/await para construir sus datos y luego páselos a la vista.

 router.get('/', async(req, res) => { // define your data var const data = { errors: {} produits: [], categories: [] } // get produits try { data.produits = await models.produit.findAll({ include: [{ model: models.image, as: "images" }, { model: models.promotionproduit, as: "promotionproduits", include: [{ model: models.promotion, as: "Promotion" }] } ] }) } catch { data.errors.produits = 'Échec du chargement des produits.' } // get categories try { // as above, do your model... } catch { data.errors.categories = 'Échec du chargement des catégories.' } res.render('home', { data }); });

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!