Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

133
Vistas
Mustache issue with array of objects

So I searched for similar question and I applied their answers but it doesn't seem to work in my case. It's frustrating 'cause it should be something simple.

So, I use mustache template to render data that come from a node server with sockets.

It works fine with one object but when I try to iterate through an array of object it just render a blank page.

This is my socket, the push is just to simulate what I'm gonna do next (get a new object in the array)

let productsTab = [{
    prodName: prodName,
    prodPrice: prodPrice,
    quantity: quantity,
    quantityUnit: quantityUnit,
    isQuantityManual: isQuantityManual,
    hasQuantityUnit: hasQuantityUnit,
    totalPrice: totalPrice
}];

productsTab.push({
    prodName: prodName,
    prodPrice: prodPrice,
    quantity: quantity,
    quantityUnit: quantityUnit,
    isQuantityManual: isQuantityManual,
    hasQuantityUnit: hasQuantityUnit,
    totalPrice: totalPrice
});

res.render('displayProduct', productsTab);

this is the log of my array

[
  {
    prodName: 'name',
    prodPrice: 'price',
    quantity: '1',
    quantityUnit: '',
    isQuantityManual: false,
    hasQuantityUnit: false,
    totalPrice: 'price'
  },
  {
    prodName: 'name',
    prodPrice: 'price',
    quantity: '1',
    quantityUnit: '',
    isQuantityManual: false,
    hasQuantityUnit: false,
    totalPrice: 'price'
  }
]

And finally this is my mustache template

{{#productsTab}}
<div>
    <div>
        {{ prodName}}
    </div>
    <div>
        {{{ prodPrice }}}
        {{ #hasQuantityUnit }}
        text
        {{ /hasQuantityUnit }}
    </div>
</div>
<div>
    <div>
        x {{ quantity }} {{ quantityUnit }}
        {{ #isQuantityManual }}
            (MAN)
        {{ /isQuantityManual }}
    </div>
    <div>
        = {{{ totalPrice }}}
    </div>
</div>
{{/productsTab}}

It works fine with just an object (not an array) without the {{#}} loop feature so the issue must come from the array...

I need some help please

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

Ok, I got it. It is when I render my template

res.render('displayProduct', productsTab);

This works only when the props you pass is an object but I had to iterate through an array of object so I did this :

res.render('displayProduct', { productsTab });

Hope it will help someone that got a brain freeze like me.

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda