【发布时间】:2019-10-28 22:34:40
【问题描述】:
我有一个数组对象
events = [
{
year: "2019",
month: "June",
title: "title",
desc: "desc"
},
{
year: "2019",
month: "June",
title: "title",
desc: "desc"
},
{
year: "2019",
month: "July",
title: "title",
desc: "desc"
},
{
year: "2018",
month: "June",
title: "title",
desc: "desc"
},
{
year: "2018",
month: "March",
title: "title",
desc: "desc"
},
{
year: "2018",
month: "March",
title: "title",
desc: "desc"
}
]
如何对数组进行排序以显示相似的年份和月份,我需要在反应组件中使用它,例如一行将显示 2019 年 6 月,另一行显示 2019 年 7 月,然后是 2018 年 6 月,依此类推,
任何帮助将不胜感激
【问题讨论】:
-
我认为 json 中的 Typo 错误
-
“相似的年份和月份”是什么意思。你有想要的结果的例子吗?
-
@NinaScholz,我需要将 2019 年,6 月显示在一行,2019 年 7 月在另一行,2018 年 6 月在另一行等,react 组件完成,我只是无法弄清楚如何对数组进行排序以获得所需的值。