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

163
Visualizações
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 à 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