Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

135
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda