2012-02-22 69 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' 
    } 
}); 
});