如何避免fullcalendar上的事件重复? [英] How to avoid events duplication on fullcalendar?

查看:855
本文介绍了如何避免fullcalendar上的事件重复?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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



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



以下是我的代码:

<$ p $ fullCalendar({
dayClick:function(date,jsEvent,view,resourceObj) {
//这里我想检查一下这个日期是否已经有'Blocked'事件,如果是的话不需要渲染另一个事件并进行另一次ajax调用
var newEvent = {
title:'Blocked',
start:date
};
$('。calendar')。fullCalendar('renderEvent',newEvent,'stick');
$ .ajax({
类型:GET,
url:block_date,
dataType:json,
data:{date:date.toJSON()},
错误:函数(结果){
$('。calendar')。fullCalendar('removeEvents',newEvent);
}
});
},
eventClick:function(calEvent,jsEvent,view){
if(calEvent.title =='Blocked'){
$('。calendar')。fullCalendar ('removeEvents',calEvent._id);
$ .ajax({
类型:GET,
url:unblock_date,
dataType:json,
data:{date:calEvent。 start.toJSON()},
error:function(result){
$('。calendar')。fullCalendar('renderEvent',calEvent);
}
}) ;
}
}
}
);

});

解决方案

找到了我的问题的答案。

  dayClick:function(date,jsEvent, fullCalendar('clientEvents',function(event){
return event.title =='Blocked'&&& event.start。){
var blockedEvents = $('。calendar' format()== date.format();
});
if(blockedEvents.length< 1){
var newEvent = {
title:'Blocked',
start:date
};
$('。calendar')。fullCalendar('renderEvent',newEvent,'stick');
$ .ajax({
类型: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({
类型:GET,
url:unblock_date,
dataType:json,
data:{date:blockedEvents [ ('。calendar')。fullCalendar('renderEvent',blockedEvents [0]);
}
});
}
},


I'm trying to avoid event duplication on same day using full calendar. I have an event called 'Blocked' and if an specific date already have a Blocked event, not allow the user to add another one.

My problem is, how to get the list of events at specific day on client side?

Here's my code:

$(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);
            }
          });
        }
      }
    }
);

});

解决方案

Found a answer to my problem. Not sure if it's the best way to deal with it, but it's working for now.

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]);
            }
          });
        }
      },

这篇关于如何避免fullcalendar上的事件重复?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆