【问题标题】:How to avoid events duplication on fullcalendar?如何避免全日历上的事件重复?
【发布时间】:2016-01-14 01:49:38
【问题描述】:

我正在尝试使用完整日历避免在同一天重复活动。 我有一个名为 'Blocked' 的事件,如果特定日期已经有一个 Blocked 事件,则不允许用户添加另一个事件。

我的问题是,如何在客户端获取特定日期的事件列表?

这是我的代码:

$(document).ready(function () {
$('.calendar').fullCalendar({
      dayClick: function (date, jsEvent, view, resourceObj) {
        // Here I would like to check if this date already have a 'Blocked' event, if yes do not need to render another event and make another ajax call.
        var newEvent = {
          title: 'Blocked',
          start: date
        };
        $('.calendar').fullCalendar('renderEvent', newEvent, 'stick');
        $.ajax({
          type: "GET",
          url: "block_date",
          dataType: "json",
          data: {date: date.toJSON()},
          error: function (result) {
            $('.calendar').fullCalendar('removeEvents', newEvent);
          }
        });
      },
      eventClick: function (calEvent, jsEvent, view) {
        if (calEvent.title == 'Blocked') {
          $('.calendar').fullCalendar('removeEvents', calEvent._id);
          $.ajax({
            type: "GET",
            url: "unblock_date",
            dataType: "json",
            data: {date: calEvent.start.toJSON()},
            error: function (result) {
              $('.calendar').fullCalendar('renderEvent', calEvent);
            }
          });
        }
      }
    }
);

});

【问题讨论】:

    标签: jquery events duplicates fullcalendar


    【解决方案1】:

    找到了我的问题的答案。不确定这是否是处理它的最佳方法,但它现在正在工作。

    dayClick: function (date, jsEvent, view) {
            var blockedEvents = $('.calendar').fullCalendar('clientEvents', function (event) {
              return event.title == 'Blocked' && event.start.format() == date.format();
            });
            if (blockedEvents.length < 1) {
              var newEvent = {
                title: 'Blocked',
                start: date
              };
              $('.calendar').fullCalendar('renderEvent', newEvent, 'stick');
              $.ajax({
                type: "GET",
                url: "block_date",
                dataType: "json",
                data: {date: date.toJSON()},
                error: function (result) {
                  $('.calendar').fullCalendar('removeEvents', newEvent);
                }
              });
            } else {
              $('.calendar').fullCalendar('removeEvents', blockedEvents[0]._id);
              $.ajax({
                type: "GET",
                url: "unblock_date",
                dataType: "json",
                data: {date: blockedEvents[0].start.toJSON()},
                error: function (result) {
                  $('.calendar').fullCalendar('renderEvent', blockedEvents[0]);
                }
              });
            }
          },
    

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-02-20
    • 1970-01-01
    • 2022-11-24
    • 2023-03-23
    • 1970-01-01
    • 2021-10-23
    • 2018-05-03
    • 2010-11-10
    相关资源
    最近更新 更多