使用 graphQL 和 React,如何按月划分 API?
Using graph QL and React, how can I divide API by month?
例如,当有大量这样的数据时:
[
{title:"string" , data:"2022-05-01", amount:10},
{title:"string" , data:"2022-04-01", amount:10},
{title:"string" , data:"2022-03-03", amount:10},
{title:"string" , data:"2022-04-01", amount:10}
]
有没有一种方法可以高效地划分和管理每个月的数据?
我想使用过滤器制作每月列表并进行管理。
(抱歉我的英语不好)
我举个例子供大家参考:
let data = [{
title: "string",
data: "2022-05-01",
amount: 10
},
{
title: "string",
data: "2022-04-01",
amount: 10
},
{
title: "string",
data: "2022-03-03",
amount: 10
},
{
title: "string",
data: "2022-04-01",
amount: 10
}
];
let monthly;
for (let i = 0; i < 12; i++) {
monthly=(data.filter(gg => {
let d = new Date(gg.data);
return (d.getMonth() == i)
}));
if (monthly.length>0){
console.log(monthly);
}
}
例如,当有大量这样的数据时:
[
{title:"string" , data:"2022-05-01", amount:10},
{title:"string" , data:"2022-04-01", amount:10},
{title:"string" , data:"2022-03-03", amount:10},
{title:"string" , data:"2022-04-01", amount:10}
]
有没有一种方法可以高效地划分和管理每个月的数据? 我想使用过滤器制作每月列表并进行管理。 (抱歉我的英语不好)
我举个例子供大家参考:
let data = [{
title: "string",
data: "2022-05-01",
amount: 10
},
{
title: "string",
data: "2022-04-01",
amount: 10
},
{
title: "string",
data: "2022-03-03",
amount: 10
},
{
title: "string",
data: "2022-04-01",
amount: 10
}
];
let monthly;
for (let i = 0; i < 12; i++) {
monthly=(data.filter(gg => {
let d = new Date(gg.data);
return (d.getMonth() == i)
}));
if (monthly.length>0){
console.log(monthly);
}
}