2012-02-22 67 views

回答

7

你会需要的是写自己的扩展fullcalendar(类似于设置有fullcalendar的gcal.js)东西,你可以调用ical.js

你应该知道写一个完整的语法分析器可能相当耗费,所以你可能想要c除非你有一个强有力的理由,否则你的后台会坚持使用谷歌日历。

你要下去深化发展自己的分机为fullcalendar的路上,你可能想看看现有的jQuery的iCal解析器(here - 免责声明:我从来没有尝试过这个插件)

-2

您可以导入将其导入Google日历,然后将Google日历导入FullCalendar。

+1

这是一个可怕的解决方案 – MarkyPython 2017-05-05 00:53:32

+0

那么它为我工作在2013年这比写一个扩展更加容易。 – 2017-05-05 19:20:20

1

我设法做到了。没有我想象的那么难。我使用ical.js作为ics解析器。解析后,我得到一个包含ics中所有信息的json对象。然后遍历它并根据the definition of FullCalendar Event object构造事件对象。

下面是代码:

$.get(calendarUrl).then(function (data) { 
// parse the ics data 
var jcalData = ICAL.parse(data.trim()); 
var comp = new ICAL.Component(jcalData); 
var eventComps = comp.getAllSubcomponents("vevent"); 
// console.log(JSON.stringify(eventComps)); 
// map them to FullCalendar events 
var events = $.map(eventComps, function (item) { 
    if (item.getFirstPropertyValue("class") == "PRIVATE") { 
     return null; 
    } 
    else { 
     return { 
      "title": item.getFirstPropertyValue("summary") + ";", 
      "start": item.getFirstPropertyValue("dtstart").toJSDate(), 
      "end": item.getFirstPropertyValue("dtend").toJSDate(), 
      "location": item.getFirstPropertyValue("location") 
     }; 
    } 
}); 

// refresh the control 
calendarCtrl.fullCalendar('destroy'); 
calendarCtrl.fullCalendar({ 
    events: events, 
    timeFormat: "H:mm", 
    displayEventEnd: true, 
    eventRender: function (event, element) { 
     // console.log(element); 
     // append location 
     if (event.location != null && event.location != "") { 
      element.append("<span>" + event.location + "</span>"); 
     } 
    }, 
    header: { 
     left: 'title', 
     center: '', 
     right: 'today,month,basicWeek,listDay prev,next' 
    } 
}); 
});