Rob*_*obG 5 javascript jquery fullcalendar
感谢StackOverflow上的另一篇文章,我在select:方法中添加了一些代码,阻止用户在NOW之前的日期添加事件.
缺点是当他们点击空的时间段,然后系统抱怨(警报消息)时,尝试的事件仍然存在.我怎么摆脱它?谢谢!
更新:这是我的代码:
select: function(start, end, jsEvent) {
var check = start._d.toJSON().slice(0,10),
today = new Date().toJSON().slice(0,10),
m = moment(),
url = "[redacted]",
result = {};
title = "Class",
eventData = {
title: title,
start: start,
end: start.clone().add(2, 'hour'),
durationEditable: false,
instructorid: 123,
locationid: 234
};
if(check < today) {
alert("Cannot create an event before today.");
$("#calendar").fullCalendar('removeEvents', function(eventObject) {
return true;
});
} else {
$.ajax({ type: "post", url: url, data: JSON.stringify(eventData), dataType: 'JSON', contentType: "application/json", success: function(result) {
if ( result.SUCCESS == true ) {
$('#calendar').fullCalendar('renderEvent', eventData, true);
$('#calendar').fullCalendar('unselect');
} else {
alert(result.MESSAGE);
}
}});
}
}
Run Code Online (Sandbox Code Playgroud)
如果您使用的是FullCalendar V2,则需要使用removeEvents方法.
您可以通过以下方式调用具有特定ID的事件来删除它:
$("#calendar").fullCalendar('removeEvents', 123); //replace 123 with reference to a real ID
Run Code Online (Sandbox Code Playgroud)
如果你想使用你自己的函数决定是否删除了一个事件,你可以这样调用它:
$("#calendar").fullCalendar('removeEvents', function(eventObject) {
//return true if the event 'eventObject' needs to be removed, return false if it doesn't
});
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
16176 次 |
| 最近记录: |