我想根据日期对数据进行分组并显示日期值及其描述,如下所示。想法是制作像 iPhone 日历一样的议程屏幕。
我的数据将如下所示:
const events = [
{ date: "2020-04-19", description: "Meeting", startTime: "11:00", endTime: "12:00" },
{ date: "2020-04-19", description: "Coference", startTime: "18:00", endTime: "19:00" },
{ date: "2020-04-20", description: "Team Coference", startTime: "18:00", endTime: "19:00" },
{ date: "2020-04-21", description: "Happy hour cocktail", },
{ date: "2020-04-22", description: "MEditation Class", },
{ date: "2020-04-24", description: "MEditation Class", },
]
当前功能:
function renderEventList() {
let today = moment().format("YYYY-MM-DD")
let tomorrow = moment().add(1, 'days').format("YYYY-MM-DD");
return events.map((d, key) => {
console.log("data1" , d);
return (
<View>
<View>
<Text>
{d.date === today ? "Today" :
d.date === tomorrow ? "Tomorrow" :
d.date}
</Text>
</View>
<Text>{d.description}</Text>
</View>
)
})
}
当前结果:
预期结果(我将管理它的样式部分)
慕无忌1623718
相关分类