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

199
Vistas
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 Respuestas
Responde la pregunta

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 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