我在我的项目中使用 fullcalendar.js,现在除了我的模态窗口外,一切正常。我正在将数据库中的数据插入到 fullcalendar.js 中!这些数据在我的日历中正确显示。如果我单击一个事件,一个模式将打开,我希望在那里显示这些数据。
我正在使用 for 循环来实现此目的,但它没有正常工作。似乎 for 循环不知道它应该在模态窗口内显示哪些数据,因此显示所有条目。这是它现在的屏幕截图:
因此,如果我单击一个事件,将打开一个包含所有条目的模式,但我想要实现的是,仅显示来 self 单击的事件的那些条目。这是我的代码:
<script type="text/javascript">
jQuery(function($) {
/* initialize the external events
-----------------------------------------------------------------*/
$('#external-events div.external-event').each(function() {
// create an Event Object (http://arshaw.com/fullcalendar/docs/event_data/Event_Object/)
// it doesn't need to have a start or end
var eventObject = {
title: $.trim($(this).text()) // use the element's text as the event title
};
// store the Event Object in the DOM element so we can get to it later
$(this).data('eventObject', eventObject);
// make the event draggable using jQuery UI
$(this).draggable({
zIndex: 999,
revert: true, // will cause the event to go back to its
revertDuration: 0 // original position after the drag
});
});
/* initialize the calendar
-----------------------------------------------------------------*/
<?php
print "var date = new Date();\n";
print "var d = date.getDate();\n";
print "var m = date.getMonth()-1;\n";
print "var y = date.getFullYear();\n";
print "var unixTimestamp = Date.now(); // in milliseconds;"
?>
var calendar = $('#calendar').fullCalendar({
//isRTL: true,
buttonHtml: {
prev: '<i class="ace-icon fa fa-chevron-left"></i>',
next: '<i class="ace-icon fa fa-chevron-right"></i>'
},
header: {
left: 'prev,next today',
center: 'title',
right: 'month,agendaWeek,agendaDay'
},
<?php
$dates=getPcalInfoOfHour($gl_userid,0,0);
print "events: [\n";
for ($x=0;$x<count($dates["id"]);$x++) {
print " {\n";
print " title: '".$dates["title"][$x]."',\n";
print " start: new Date(".date("Y",$dates["start"][$x]).", ".(date("n", $dates["start"][$x]) - 1).", ".date("j",$dates["start"][$x]).", ".date("G",$dates["start"][$x]).", ".date("i",$dates["start"][$x]).",0,0),\n";
print " end: new Date(".date("Y",$dates["end"][$x]+1).", ".(date("n", $dates["end"][$x]+1) - 1).", ".date("j",$dates["end"][$x]+1).", ".date("G",$dates["end"][$x]+1).", ".date("i",($dates["end"][$x]+1)).",0,0),\n";
print " allDay: false,\n";
print "durationEditable : false,\n";
print " className: 'label-info',\n";
if ($dates["type"][$x]=="PM") {print "backgroundColor: '#000000',\n";}
if ($dates["type"][$x]=="AM") {print "backgroundColor: '#D15B47',\n";}
if ($dates["type"][$x]=="SM") {print "backgroundColor: '#FFB752',\n";}
if ($dates["type"][$x]=="S") {print "backgroundColor: '#87B87F',\n";}
if ($dates["type"][$x]=="SS") {print "backgroundColor: '#4F99C6',\n";}
if ($dates["type"][$x]=="MJ") {print "backgroundColor: '#A069C3',\n";}
if ($dates["type"][$x]=="PR") {print "backgroundColor: '#5A5A5A'\n";}
if ($x<(count($dates["id"])-1)) {
print " },\n";
} else {
print " }\n";
}
}
print "]\n";
timeFormat: 'h:mm'
?>
,
editable: true,
droppable: true, // this allows things to be dropped onto the calendar !!!
drop: function(date, allDay) { // this function is called when something is dropped
// retrieve the dropped element's stored Event Object
var originalEventObject = $(this).data('eventObject');
var $extraEventClass = $(this).attr('data-class');
// we need to copy it, so that multiple events don't have a reference to the same object
var copiedEventObject = $.extend({}, originalEventObject);
// assign it the date that was reported
copiedEventObject.start = date;
copiedEventObject.allDay = allDay;
if($extraEventClass) copiedEventObject['className'] = [$extraEventClass];
// render the event on the calendar
// the last `true` argument determines if the event "sticks" (http://arshaw.com/fullcalendar/docs/event_rendering/renderEvent/)
$('#calendar').fullCalendar('renderEvent', copiedEventObject, true);
// is the "remove after drop" checkbox checked?
if ($('#drop-remove').is(':checked')) {
// if so, remove the element from the "Draggable Events" list
$(this).remove();
}
}
,
selectable: true,
selectHelper: true,
select: function(start, end, allDay) {
calendar.fullCalendar('unselect');
}
,
eventClick: function(calEvent, jsEvent, view) {
//display a modal
var modal =
'<div class="modal fade">\
<div class="modal-dialog">\
<div class="modal-content">\
<div class="modal-body">\
<?php for ($x=0;$x<count($dates["id"]);$x++) { ?>
<button type="button" class="close" data-dismiss="modal" style="margin-top:-10px;">×</button>\
<label> <strong>Topic:</strong> <?php echo $dates["type"][$x] ?></label>\
<label> <strong>Selected Start:</strong> <?php echo $dates["start"][0]?></label>\
<label> <strong>Selected End:</strong> <?php echo $dates["end"][0] ?></label>\
<label> <strong>Title:</strong> <?php echo $dates["title"][0] ?></label>\
<label> <strong>Location:</strong> <?php echo $dates["location"][0] ?></label>\
<label> <strong>Address:</strong> <?php echo $dates["adress"][0] ?></label>\
<label> <strong>Phone:</strong> <?php echo $dates["phone"][0] ?></label>\
<?php } ?>
</div>\
<div class="modal-footer">\
<button type="button" class="btn btn-sm" data-dismiss="modal"><i class="ace-icon fa fa-times"></i> Close Window</button>\
</div>\
</div>\
</div>\
</div>';
var modal = $(modal).appendTo('body');
modal.modal('show').on('hidden', function(){
modal.remove();
});
console.log(calEvent.id);
console.log(jsEvent);
console.log(view);
// change the border color just for fun
//$(this).css('border-color', 'red');
}
});
})
</script>
有人能告诉我我做错了什么吗?我的代码应该是什么样子才能正常工作?
最佳答案
我遇到的情况与此完全相同。我所做的是使用 fullcalendar 的内置 clickHandler JavaScript 函数来获取日历项的 ID。
然后我使用 AJAX 调用我的 PHP 文件从数据库中提取相关的项目详细信息,然后将它们附加到模态。
关于javascript - fullcalendar.js - 将 for 循环插入模态,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33213186/