简体   繁体   English

在 Ionic2_Calendar 中加载事件

[英]Loading Events in Ionic2_Calendar

I implemented a version of the ionic2-Calender.我实现了 ionic2-Calender 的一个版本。 It works very fine.它工作得很好。 When i have no events in my eventSource and create an Event, the event is displayed correctly.当我的eventSource中没有事件并创建一个事件时,该事件将正确显示。 The Problem comes when I am trying to load Events from my Storage.当我尝试从存储中加载事件时,问题就来了。 I am always getting this error:我总是收到这个错误:

TypeError: eventStartTime.getFullYear is not a function at MonthViewComponent.onDataLoaded (ionic2-calendar.js:1768) at MonthViewComponent.ngOnChanges (ionic2-calendar.js:1614) at MonthViewComponent.wrapOnChangesHook_inPreviousChangesStorage TypeError: eventStartTime.getFullYear is not a function at MonthViewComponent.onDataLoaded (ionic2-calendar.js:1768) at MonthViewComponent.ngOnChanges (ionic2-calendar.js:1614) at MonthViewComponent.wrapOnChangesHook_inPreviousChangesStorage

Can anyone help me?谁能帮我?

Based on the issue here , it says the startTime property of the event should be a date object.根据这里的问题,它说事件的 startTime 属性应该是日期 object。

This indicates that the event startTime probably is not a valid Date object.这表明事件 startTime 可能不是有效的日期 object。 Could you double check what's the type of startTime?你能仔细检查一下 startTime 的类型是什么吗? If it's a string, you need to convert it into Date object.如果是字符串,则需要将其转换为Date object。

I have also stumbled upon this when using web storage to load the calendar, which gets converted to string data type.在使用 web 存储加载日历时,我也偶然发现了这一点,该日历被转换为字符串数据类型。

The solution is very simple as we only need to iterate through the value from the storage and convert it to date before setting the value of the model itself.解决方案非常简单,因为我们只需要遍历存储中的值并将其转换为日期,然后再设置 model 本身的值。

var eventsFromStorage = window.localStorage.get("eventsCalendar");
var countData = eventsFromStorage.length;

for (i = 0; i < countData; i++) {
  eventsFromStorage[i].startTime = new Date(eventsFromStorage[i].startTime);
  eventsFromStorage[i].endTime = new Date(eventsFromStorage[i].endTime);
}

this.eventsModel = eventsFromStorage;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM