创建基本的iCalendar(Creating basic iCalendar)
Start off creating the basic data structure and set a property on that:
如下所示,开始创建基本的数据结构,并为其设置一个属性:
var comp = new ICAL.Component(['vcalendar', [], []]);
comp.updatePropertyWithValue('prodid', '-//iCal.js Wiki Example');
You can get the resulting iCalendar by calling comp.toString()
at any time:
然后,您可以随时调用comp.toString()
来获取生成的iCalendar:
comp.toString();
// BEGIN:VCALENDAR
// PRODID:-//iCal.js Wiki Example
// END:VCALENDAR
Sub-components are created as needed and attached to the appropriate place in the “tree”:
可以根据业务需要创建子组件,将其插入到“树”中正确的位置即可:
var vevent = new ICAL.Component('vevent'),
event = new ICAL.Event(vevent);
// Set standard properties
event.summary = 'foo bar';
event.uid = 'abcdef...';
event.startDate = jsical.Time.now();
// Set custom property
vevent.addPropertyWithValue('x-my-custom-property', 'custom');
// Add the new component
comp.addSubcomponent(vevent);
Printing the full calendar now:
现在将完整的iCalendar结果打印如下:
comp.toString();
// BEGIN:VCALENDAR
// PRODID:-//iCal.js Wiki Example
// BEGIN:VEVENT
// SUMMARY:foo bar
// UID:abcdef...
// DTSTART:20161031T122128
// X-MY-CUSTOM-PROPERTY:custom
// END:VEVENT
// END:VCALENDAR