【问题标题】:Delete only one event from a series of events with jquery fullcalendar 1.5使用 jquery fullcalendar 1.5 从一系列事件中仅删除一个事件
【发布时间】:2011-04-23 17:54:06
【问题描述】:

假设我有一个每天重复的事件。现在用户想要删除星期一的事件,但保留所有其余的。我怎样才能做到这一点?现在,由于它们都具有相同的重复 ID,它将删除所有事件。我只想删除一个事件。

是否有其他东西可以删除,然后是 Id?就像我不能在事件中使用我自己的属性来删除它吗?

【问题讨论】:

  • 您好,您是如何解决这个问题的?你能举个例子吗?

标签: jquery jquery-plugins fullcalendar


【解决方案1】:

是的,您可以使用自己的属性。但是您需要在加载事件时在服务器端生成它们。

例如(我将以数组为例)

{
events: [
    {
        title: 'Event1',   //required
        start: '2011-04-04',    //required
        myUniqueID: '000001' //your UniqueID thats embedded in the event!
        className: 'id000001'    //your UniqueID that appears as a class on DOM and get directly using jquery

    },
    {
        title: 'Event2',
        start: '2011-05-05'
        myUniqueID: '000002' //your UniqueID thats embedded in the event!
        myOtherUnqieID: 'allYearOnly',
        yetAnotherUniqueID: 'userDelete:no',
        myBooleanID: false,   //not enclosed in '' !!
        className: 'id000002'    //your UniqueID that appears as a class on DOM and get directly using jquery
    }
    // etc...
],
color: 'yellow',   // an option for the whole source
textColor: 'black' // an option for the whole source

}

http://arshaw.com/fullcalendar/docs/event_data/Event_Object/

了解非标准字段

【讨论】:

  • @ppumkin - 我知道非标准字段,但从我的尝试看来,您不能使用非标准字段从日历中删除事件(使用 removevents)。如果你知道如何请告诉我。
  • 嗯.. 我想我知道你的意思。您正在尝试从源中删除事件。使用 arshaw.com/fullcalendar/docs/event_data/removeEvents 这个函数而不是把 ID 只使用你的唯一字段。我从来没有这样做过——但我想很快我将不得不做类似的事情。但也许试试这个?
  • @ppumkin - 是的,我正在尝试将其从日历对象中删除。因此,当该人单击事件的视图然后单击“仅删除此实例”时,他单击它应该从日历中消失并且永远不会回来(它从数据库中消失了)。我试图将我自己的独特字段传递给 removeEvents 但它什么也没做。我认为它使用id。到目前为止,我提出的 2 个解决方案是。 ID 对于所有事件都是 unquie 并且永远不会重复。然后在服务器端检查它是否重复。当然有一个代价是完整的日历没有重复的知识或事件。
  • 第二种方法可能是单击在该事件上放置一个标记,然后使用 jquery 将其删除,但我不确定这是否会将其从内部集合中删除,或者使用任何完整的日历来存储它.另外,跟踪记录更多。现在我选择了第一种方法,但一直在寻找更好的方法。
  • 是的 - 但问题是提要来自哪里?也许单击时您必须将自定义参数发送到您的 ajaxDelete.aspx/php;处理请求服务器端;并重新加载源...?
【解决方案2】:

如果您将 id 属性设置为事件(不是 myUniqueId,它是一个自定义属性),那么您可以使用以下方法删除一个或多个具有此类 id 的事件:

.fullCalendar("removeEvents", "your_event_id_here")

【讨论】:

  • 你不必设置id。查看我的解决方案。
【解决方案3】:

当你有你所有的 id 集时,使用 Izet idea。

但是当您的活动中没有 id 时,请这样做(当您设置了 id 时也可以这样做):

eventClick: function(event){
   $('#myCalendar').fullCalendar('removeEvents',event._id);
}

我已弄清楚为什么会出现以下问题: How do I delete this event from FullCalendar?

【讨论】:

    【解决方案4】:

    我为这个答案创建了一个完整的特定解决方案,这恰好非常简单。秘诀是使用自定义属性(在我的情况下为 excludeDate),其中包括要从每日并发事件中排除的日期。 然后,在 eventRender 函数中,到达该日期时返回 false。

    eventRender: function(event, element, view) {
    
        var theDate = event.start
        var excludedDate = event.excludedDate;
        var excludedTomorrrow = new Date(excludedDate);
         //if the date is in between August 29th at 00:00 and August 30th at 00:00 DO NOT RENDER
        if( theDate >= excludedDate && theDate < excludedTomorrrow.setDate(excludedTomorrrow.getDate() + 1) ) {
            return false;
        }
        }
    

    转到working demo on jsfiddle

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2014-11-09
      • 1970-01-01
      • 2018-08-08
      • 1970-01-01
      • 2017-10-05
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多