我在我的項目中使用fullcalendar.js,現在一切正常,除了我的模態窗口。我將數據庫中的數據插入fullcalendar.js!這些數據在我的日曆中正確顯示。如果我點擊一個事件模式打開,我希望顯示這些數據。fullcalendar.js - 將循環插入模態
我正在使用for-loop來實現這個功能,但它不能正常工作。看起來for循環不知道它應該在模態窗口內顯示哪些數據,因此所有的條目都顯示出來。這裏是什麼樣子,現在的截圖:
所以,如果我點擊一個事件,一個模式的所有條目打開,但我想實現的是,只有那些條目將顯示其來自我點擊的事件。這是我的代碼:
<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>
有人能告訴我我做錯了什麼嗎?我的代碼應該是什麼樣子才能工作?
你能告訴我在我的代碼中fullcalender.js事件選項用下面的代碼我需要什麼更改?我不擅長js函數或JAVA,因此我不知道我的代碼應該是什麼樣子。 –