How would I add / remove an event from the jquery-calendar plugin?
I can initialize the calendar with a bunch of events, but I'm unsure how to programmatically add/remove (programmatically) an event to the calendar.
How would I add / remove an event from the jquery-calendar plugin?
I can initialize the calendar with a bunch of events, but I'm unsure how to programmatically add/remove (programmatically) an event to the calendar.
添加:
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');