jquery-calendar以编程方式添加/删除事件



如何从jquery日历插件中添加/删除事件?

我可以使用一堆事件初始化日历,但我不确定如何以编程方式(以编程方式)向日历添加/删除事件。

添加:

var event = {....} // initialize your new calendar event
var cal = $('#your_calendar_id').data('cal');
cal.target.cal('add', event);

无法删除(默认情况下)。 我为此添加了 2 个方法(到 jquery.calendar.js):

/**
         * Remove an event object to the calendar
         *
         * @param mixed uid     : The UID of the event that we want to remove.
         *
         * @scope public.
         */
        remove : function( uid ){           
            // Get shortcuts to calendar container and data.
            var $this = $(this),
            $event,
            data = $this.data(plugin_name);
            // If the calendar has been set up already...
            if( data ){
                // Find the event element.
                $event = data.cache.events[i];
                // IF we find one, we'll remove it.
                if( $event ){
                    //$($event).remove();
                    //_private.event.remove.apply( $event );
                    delete data.cache.events[uid];
                }
            }
        },
        /**
         * Clear all event objects from the calendar
         *
         * @scope public.
         */
        clear : function(){         
            // Get shortcuts to calendar container and data.
            var $this = $(this),
            data = $this.data(plugin_name);
            // If the calendar has been set up already...
            if( data ){
                for( i in data.cache.events ){
                    //data.cache.events[i].elems.remove();
                    data.target.cal('remove', i);
                }               
            }
        },

要使用它们,您可以执行以下操作:

// To remove an event
var eventId = 5 // Get your event id
var cal = $('#your_calendar_id').data('cal');
cal.target.cal('remove', eventId);
// To clear all appointments from the calendar
cal.target.cal('clear');

最新更新