代码之家  ›  专栏  ›  技术社区  ›  Ali Tarhini

如何在创建事件后更新jquery FullCalendar约会

  •  2
  • Ali Tarhini  · 技术社区  · 14 年前

    我必须调用或处理什么事件或方法名称来更新日历中的现有事件(我单击的事件)。完整的日历可以在这里找到 http://arshaw.com/fullcalendar/

    2 回复  |  直到 14 年前
        1
  •  3
  •   Lukman    14 年前

    var calendar = $('#calendar');
    var curr_event = null;
    calendar.fullCalendar({
        ...
    
        events: [],
        eventClick: function(event, jsEvent, view) {
            curr_event = event;
            show_form_or_something();
        },
    
        ...
    });
    

    为了允许用户修改事件属性(title、start等),您可能需要显示一个窗体或其他内容。然后在FullCalendar实例中更新事件:

    $.extend(curr_event, {
        title: 'New Event Title',
        start: new Date()
    });
    calendar.fullCalendar('updateEvent', curr_event);
    

    为了回答jmeho的问题:

    将事件添加到FullCalendar时 renderEvent() 或事件源,可以指定 id

    var event_obj = calendar.fullCalendar('clientEvents', 'specific event id');
    

    然后可以修改has/对象并使用updateEvent()方法更新FullCalendar显示。

        2
  •  1
  •   António Almeida Michal Drozd    12 年前

    此代码非常适合在更新事件后更新日历。
    首先移除日期事件,然后再次渲染它。

    function updateCalenderUP(id, title, Sessiontitle, SessionStart, Sessionend, color) {    
        title = title;
        var id1 = id;
    
        $('#calendar').fullCalendar( 'removeEvents', id1);
        $('#calendar').fullCalendar('refresh');
        title = title; 
    
        if (title) {
            calendar.fullCalendar('renderEvent', {
                    id: Eventid,
                    title: title,
                    start:startDate,
                    end: EndDate,                                
                    allDay: false,
                    backgroundColor:color
                }, true // make the event "stick"
            );
        }
        calendar.fullCalendar('unselect');
    }