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

200
Visualizações
mapping when using conditional statement

Hope someone can help,

On my site a user can log in and post a notice to the home page, they can then see all their notices and the user that posted the notice.

To show the notice author I am using the below map.

<% notices.map(notice => notice.author.username ) %>
<%= notice.author.username %>

Then I'm trying to say if there is no notice author (as in that user was deleted from the database) i want it to say "Author Unknown"

 <% if (!notice.author.username) { %>
     <p>Author Unknown</p>
 <% } else {%>
      <% notices.map(notice => notice.author.username ) %>
      <%= notice.author.username %>
 <% } %>

but the map seems to stop working in the conditional statement, any idea's???

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

Use,

<%- notices.map(notice => notice.author.username ) %>

Instead,

<% notices.map(notice => notice.author.username ) %>

The Javascript functions should be wrapped around <%- %>

If that does not work then ,

Try using for loop or forEach.

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