将事件添加到事件日历中

时间:2015-08-08 10:07:59

标签: javascript fullcalendar

如何将事件添加到另一个事件中?

例如

$('#calendar').fullCalendar({
  events: [
    {
      start: new Date(),
      end: new Date(),

      events: [ {}, {} ] // ??? 
    }  
  ]
});

请参阅screenshot

1 个答案:

答案 0 :(得分:0)

如果没有大量的自定义修改,这是不可能的。非常超出SO问题的范围。

你最容易接近的是使用背景事件作为"父母"作为儿童活动的活动和定期活动。如下所示:

var sourceEvents = [
    {
        id: 1,
        start: moment(),
        end: moment().add(6,'h'),
        childEvents: [{
            start: moment().add(1,'h'),
            end: moment().add(2,'h'),
        }, {
            start: moment().add(3,'h'),
            end: moment().add(5,'h'),
        }],
    }
];

$("#calendar").fullCalendar({
    defaultView: "agendaWeek",
    events: function( start, end, timezone, callback ) {
        var events = [];
        sourceEvents.forEach(function(event){
            event.rendering = "background";
            events.push(event);
            event.childEvents.forEach(function(childEvent){
                // you could do some checks to make sure they are in bounds
                // you could also do some color coding here
                childEvent.parentId = event.id;
                events.push(childEvent);
            });
        });
        callback(events);
    },
});

JSFiddle