如何将以下数组分组并将其输出在EJS中?
这是数组:
const emails = [
{ email: 'w@w', createdAt: 2022-03-31T17:07:36.675+00:00 },
{ email: 'a@a', createdAt: 2022-03-31T17:07:36.675+00:00 },
{ email: 'w@b', createdAt: 2022-04-31T17:07:36.675+00:00 },
{ email: 'w@c', createdAt: 2022-04-31T17:07:36.675+00:00 },
{ email: 'w@d', createdAt: 2022-06-31T17:07:36.675+00:00 },
]
我想在 ejs 中将其格式化为这样:
<div class='card'>
<h3>Unique Date</h3>
<div class='emails'>
<p>All the emails of that unique date</p>
</div>
</div>
我该怎么做?
This is the array:
const emails = [
{ email: 'w@w', createdAt: 2022-03-31T17:07:36.675+00:00 },
{ email: 'a@a', createdAt: 2022-03-31T17:07:36.675+00:00 },
{ email: 'w@b', createdAt: 2022-04-31T17:07:36.675+00:00 },
{ email: 'w@c', createdAt: 2022-04-31T17:07:36.675+00:00 },
{ email: 'w@d', createdAt: 2022-06-31T17:07:36.675+00:00 },
]
I want to format it like this in ejs:
<div class='card'>
<h3>Unique Date</h3>
<div class='emails'>
<p>All the emails of that unique date</p>
</div>
</div>
How can I do that?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在后端,您将需要使用reduce 和map 对现有数组进行分组以执行以下操作。
然后,您需要将
groupedEmailArray
传递到您的视图并像这样渲染视图这应该会产生您正在寻找的结果。
In your back end you will want to use reduce and map to group your existing array to do the following.
You will then want to pass
groupedEmailArray
to your view and render the view like thisThis should yield the result you are looking for.