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

时间:2013-09-10 20:47:11

标签: jquery jquery-plugins

如何在jquery-calendar插件中添加/删除活动?

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

1 个答案:

答案 0 :(得分:0)

添加:

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');