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

210
Visualizações
How can I control where an item is placed in a dynamically rendered EJS list?

I have an <ol> in EJS that consists of info obtained from objects in a database. As I make new objects, the list gets a new <li> with their information. These objects all have a date as their first field.

Is it possible to have the <ol> sort itself chronologically based on this date field? i.e., nearest date is '1' in the list, but if an object with an earlier date is added it will become '1' and the previous near date becomes '2'. The date is also contained in its own <span> within the list.

Here's what my EJS is looking like for now:

    <ol class="shows">
    <% for(let i=0; i < info.length; i++) {%>
        <li class="show">
            <span class="bold"><%= info[i].date %></span><span>  </span><span><%= info[i].bands %></span><span> - </span><span><%= info[i].venue %></span><span> - </span><span><%= info[i].ticketPrice %></span><span> - </span><span><%= info[i].startTime %></span><span> - </span><span><a href="<%= info[i].ticketLink %>">♣</a></span>
        </li>
    <% } %>
    </ol>
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

Simply sort your array...

info.sort((a,b)=> b-a)
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