如何在JS地图功能中分组
我有一些来自DB的数据:
{InteractionDate: '2022-07-07', Time: 10, ID: 'eac61b7e-8e25-4445-ad1d-f1ee8c6ac86c'}
{InteractionDate: '2022-07-07', Time: 20, ID: 'c3a78dbe-553d-4ecc-b4ef-8d8d3039c521'}
{InteractionDate: '2022-07-07', Time: 33, ID: 'c3a78dbe-553d-4ecc-b4ef-8d8d3039c521'}
{InteractionDate: '2022-07-07', Time: 30, ID: '229530ed-ca44-4015-b1d7-b528be5b6071'}
我需要在UI中显示它:
Month Time # of Unique ID's
===== ==== ================
07/22 93 3
ID是我需要一些帮助的新增加。现在,我正在使用它来分组所有日期并总结时间。
const groupedArray = _(allInteractions)
.groupBy(v => moment(v.InteractionDate).format('MM/YYYY'))
.map((item, date) => ({
interactionDate: date,
totalSec: _.sumBy(item, 'Time')
//uniqueIDs: ?
}))
.value();
问题是 - 我怎么知道07/22中看到了多少个不同的ID?
I have some data coming from the DB:
{InteractionDate: '2022-07-07', Time: 10, ID: 'eac61b7e-8e25-4445-ad1d-f1ee8c6ac86c'}
{InteractionDate: '2022-07-07', Time: 20, ID: 'c3a78dbe-553d-4ecc-b4ef-8d8d3039c521'}
{InteractionDate: '2022-07-07', Time: 33, ID: 'c3a78dbe-553d-4ecc-b4ef-8d8d3039c521'}
{InteractionDate: '2022-07-07', Time: 30, ID: '229530ed-ca44-4015-b1d7-b528be5b6071'}
and I need to show it in the UI like so:
Month Time # of Unique ID's
===== ==== ================
07/22 93 3
The ID's is a new addition that I need some help with. Right now, I'm using this to group all the dates and sum the times.
const groupedArray = _(allInteractions)
.groupBy(v => moment(v.InteractionDate).format('MM/YYYY'))
.map((item, date) => ({
interactionDate: date,
totalSec: _.sumBy(item, 'Time')
//uniqueIDs: ?
}))
.value();
The question is - How do I know how many DIFFERENT id's were seen in 07/22?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我的解决方案不是那么漂亮,但是它正在起作用
My solution is not that pretty, but it's working
这是使用内置
set
运算符进行的香草JS方法。Here is a vanilla JS way to do it using the built-in
Set
operator.