我尝试了许多来自互联网的解决方案,但无法找到正确的答案,或者我做错了。所以我要做的就是drop:function {}一旦外部元素被删除就会调用ajax,然后当得到结果返回时,这将是我想作为id存储到当前事件中的rowid。
我尝试了一些代码,但它不能正常工作:(
这是我的代码:
drop: function(date, jsEvent, ui) {
//Call when you drop any red/green/blue class to the week table.....first time runs only.....
var array = calendar.fullCalendar("clientEvents");
var resourceId = array[counter]['resourceId'];
classid = $(this).data('classid');
color = $(this).data('color');
var defaultDuration = moment.duration($('#mycalendar').fullCalendar('option', 'defaultTimedEventDuration'));
var end = date.clone().add(defaultDuration); // on drop we only have date given to us
//console.log('end is ' + end.format());
var startTime = date.format("H:mm");
var endTime = end.format("H:mm");
var disalert = "ResourceId: "+resourceId+"\nClassid: "+classid+"\nStart Time: "+date.format("H:mm")+"\nEnd Time: "+end.format("H:mm");
//alert(disalert);
counter++;
//console.log(array[0]['resourceId']);
$.ajax({
type: 'POST',
data: {resource_id: resourceId, class_id: classid, start_time: startTime, end_time: endTime},
url: 'fullcalendar_insert.php',
success: function(data) {
//$(this).data("rowid",data);
var desc = '1';
// retrieve the dropped element's stored Event Object
var originalEventObject = $(this).data('eventObject');
var copiedEventObject = $.extend({}, originalEventObject);
copiedEventObject.id = "1";
$('#mycalendar').fullCalendar('updateEvent', copiedEventObject, true);
// we need to copy it, so that multiple events don't have a reference to the same object
/*var copiedEventObject = $.extend({}, originalEventObject);
copiedEventObject.start = startTime;
copiedEventObject.end = endTime;
//copiedEventObject.id = classid;
copiedEventObject.color = color;
copiedEventObject.description = desc+'_custom_event';
console.log(copiedEventObject);
$('#mycalendar').fullCalendar('renderEvent', copiedEventObject, true);*/
}, error: function() {
alert("Please try again later!");
}
});
谢谢你们。