我使用react native calendars尝试使用onVisibleMonthsChange
更新每个月的事件,我的状态正在更新正确的数据,但日历显示为空,有什么想法吗?
CalendarList无法使用loadItems(dates)
使用CalendarList
参数之间的事件填充dates
。我正在事件缩减工具中创建数据:
const newItems = {};
for (let i = 0; i < 180; i++) {
const time = moment().utc() + i * 24 * 60 * 60 * 1000;
const strTime = timeToString(time);
if (events[strTime]) {
newItems[strTime] = { ...events[strTime] };
} else {
newItems[strTime] = {};
}
}
return {
...newItems
};
在我的月份组件中,我从componentDidMount
开始称呼它
const { componentDidMount() {
const {
credentials: { year, group, id },
fetchEvents
} = this.props;
const Id = id || group;
fetchEvents(Id);
}
然后我使用loadItems
参数将相关日期标记为选定日期:
loadItems(dates) {
const { events } = this.props;
const moment = extendMoment(Moment);
const lastItemIndex = dates.length;
const startDate = moment(dates[0].timestamp).startOf("month"),
endDate = moment(dates[lastItemIndex - 1]).endOf("month");
const dateRange = moment().range(startDate, endDate);
newEvents = Object.keys(events).reduce((output, dateString) => {
if (dateRange.contains(moment(dateString).toDate())) {
output[dateString] = events[dateString];
if (!helpers.emptyObject(output[dateString])) {
output[dateString].selected = true;
}
}
return output;
}, {});
this.setState({
markedDates: { ...newEvents, ...this.state.markedDates }
});
}
链接到仓库:
一个月不显示: