使用calendarList,onVisibleMonthsChange={this.loadItems}
不更新markedDates
我的 loadItems 函数是:
loadItems(months) {
const { events, eventsForMonth } = this.props;
eventsForMonth(events, months);
}
<CalendarList
style={styles.calendar}
current={currentDate}
markingType={"multi-dot"}
onVisibleMonthsChange={this.loadItems}
onDayPress={this.onDayPress}
minDate={currentDate}
loadingIndicatorColor={"#6da1a6"}
markedDates={eventsMonth}
pastScrollRange={0}
futureScrollRange={6}
scrollEnabled={true}
showScrollIndicator={true}
/>
我使用以下内容为每个月创建事件reducer
,在初始渲染时,我为循环创建自己的时间戳:
export function eventsForMonth(state = {}, action) {
switch (action.type) {
case "EVENTS_CALENDAR_MONTH": {
const { data, day } = action;
if (!day) {
const currentDate = helpers.currentDate;
const timestamp = Date.parse(currentDate);
const day = [{
timestamp
}]
}
const newItems = {};
for (let i = -15; i < 20; i++) {
const time = day[0].timestamp + i * 24 * 60 * 60 * 1000;
const strTime = timeToString(time);
if (data[strTime]) {
newItems[strTime] = { ...data[strTime] };
} else {
newItems[strTime] = {};
}
}
return {
...newItems
};
}
default:
return state;
}
}
我eventsMonth
的滚动后以正确的格式显示正确的数据,为什么我的月份没有呈现?
{
"2018-11-24": {},
"2018-11-25": {},
"2018-11-26": {},
"2018-11-27": {},
"2018-11-28": {},
"2018-11-29": {},
"2018-11-30": {},
"2018-12-01": {
"dots": [
{
"id": 2983,
"title": "Kiranjit Event",
"colour": "",
"textColor": "#000000",
"organiser": "N/A",
"description": "",
"selectedDotColor": "",
"categories": [
{
"name": "Student 1 - Kiranjit Aujla",
"slug": "student-1-spc",
"term_group": 0,
"term_taxonomy_id": 107,
"taxonomy": "tribe_events_cat",
"description": "",
...
}
],
"startTime": "08-00",
"endTime": "17-00"
}
],
"disabled": false,
"selected": true,
"selectedColor": "#00CCCB",
"customStyles": {
"text": {
"marginTop": 3
}
}
},
"2018-12-02": {},
"2018-12-03": {}
}