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

161
Vistas
show only one item with express/ejs/mongo

I've been trying to make a very simple ToDo list but when I want to show the description of the tasks, it displays all the descriptions, not only for that task itself. See the image, I want only one description by each task. Whats happening

I'm using a forEach loop but idk if I should create a new variable to receive only the description of tasks. What can I do to show only one item from description and that's refer to the task.

Here is the EJS file:

<% todo.forEach(function(task) { %>
    <div class="itens">
        <li>
            <a class="item" href="/edit/<%= task._id %>">
                <%= task.task %>
            </a>
            <a class="item del-btn" href="/delete/<%= task._id %>" onclick="return confirm('Deseja excluir?');">
                <img class="trash-icon" src="/images/trash.png" alt="">
            </a>
            <a class="item del-btn" href="/delete/<%= task._id %>" onclick="return confirm('Tarefa Concluida?');">
                <img class="trash-icon" src="/images/done.png" alt="">
            </a>
            <% todo.forEach(function(desc) { %>
                <p>
                    <%= desc.desc %>
                </p>
            <% }); %>
        </li>
    </div>
<% }); %>

Hey, I figure out what was the problem here. The second loop is what makes the description show duplicated and not only for the task. Just erase the second loop and changes the <%= desc.desc %> to <%= task.desc %> and will work fine!

over 4 years ago · Santiago Trujillo
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