如何控制将项目放置在动态渲染的EJS列表中的位置?
我在EJ中有一个< ol>
,该>由从数据库中的对象获得的信息组成。当我制作新对象时,列表将获得新的< li>
以及其信息。这些对象都有一个日期作为其第一个字段。
是否可以根据此日期字段按时间顺序排序< ol>
?即,列表中最接近的日期为“ 1”,但是如果添加了较早日期的对象,它将变为“ 1”,并且前面的接近日期变为'2'。该日期还包含在其自己的< span>
中。
这就是我的EJS现在的样子:
<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>
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>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
只需对您的数组排序...
Simply sort your array...