【发布时间】:2021-10-03 01:31:57
【问题描述】:
我有以下几点:
currentPhase: {
endDate: "2030-12-31T09:00:00.000Z"
startDate: "2021-06-26T11:00:00.000Z"
status: "ended"
}
还有一个有更多对象的对象:
phases: {
ended: {
startDate: "2021-06-26T11:00:00.000Z",
endDate: "2030-12-31T09:00:00.000Z"},
openingSoon: {
startDate: "1899-12-31T21:00:00.000Z",
endDate: "2021-06-17T09:25:31.000Z" },
playing: {
startDate: "2021-06-15T21:00:00.000Z",
endDate: "2021-08-30T21:00:00.000Z" },
readyToPlay: {
startDate: "2021-06-13T11:00:00.000Z",
endDate: "2021-06-15T21:00:00.000Z" },
registrationsOpen: {
startDate: "2021-06-07T19:00:00.000Z",
endDate: "2021-06-12T17:00:00.000Z" },
resultsPending: {
startDate: "2021-08-30T21:00:00.000Z",
endDate: "2021-06-26T11:00:00.000Z" },
}
CurrentPhase 会经常变化,每当 CurrentPhase 变化时,我都需要根据 currentPhase 从 phases 中选择下一个阶段。
我尝试的是根据 currentPhase 的 endDate 过滤阶段(因为它不是数组,所以它不起作用),我也可以做的是阶段 [currentPhase.status],但是我如何检索当前阶段[currentPhase.status] 的索引以便在阶段[currentPhase.status] 之后选择下一个对象以显示它的开始日期?
提前致谢!
【问题讨论】:
标签: javascript reactjs filter filtering indexof