我正在研究 fullCalendar 并尝试获取事件信息以显示在弹出模式中(单击事件时)。
但是,我只能显示活动标题、位置、开始日期和结束日期。
我还需要显示开始时间和结束时间。我究竟做错了什么?
我的代码如下:
eventClick: function(event, jsEvent, view) {
var startdate= new Date(event.event.start);
var enddate= new Date(event.event.end);
var starttime= new Date(event.event.startTime);
var endtime= new Date(event.event.endTime);
//console.log(event);
$('#modalID').html(event.event.id);
$('#modalTitle').html(event.event.title);
$('#modalLocation').html(event.event.extendedProps.location);
$('#modalStartDate').html(moment(startdate.getTime()).format("DD-MM-YYYY"));
$('#modalStartTime').html(moment(starttime.getTime()).format("hh:mm A"));
//moment("01:15:00 PM", "h:mm:ss A").format("HH:mm:ss")
$('#modalEndDate').html(moment(enddate.getTime()).format("DD-MM-YYYY"));
$('#modalEndTime').html(moment(endtime.getTime()).format("hh:mm A"));
$('#fullCalModal').modal();
},
我的更新代码如下
<script>
document.addEventListener('DOMContentLoaded', function() {
var calendarEl = document.getElementById('calendar');
var calendar = new FullCalendar.Calendar(calendarEl, {
plugins: [ 'interaction', 'dayGrid' ],
defaultDate: '<cms:date format='Y-m-d' />',
editable: true,
eventLimit: true, // allow "more" link when too many events
displayEventTime: false,
events: [
<cms:pages masterpage='events.php' show_future_entries='1'>
{
id: <cms:escape_json><cms:show k_page_id /></cms:escape_json>,
title: <cms:escape_json><cms:show k_page_title /></cms:escape_json>,
location: <cms:escape_json><cms:show location /></cms:escape_json>,
start: <cms:escape_json><cms:show start_date /></cms:escape_json>,
startTime: <cms:escape_json><cms:show start_time /></cms:escape_json>,
end: <cms:escape_json><cms:show end_date /></cms:escape_json>,
endTime: <cms:escape_json><cms:show end_time /></cms:escape_json>
}<cms:if "<cms:not k_paginated_bottom/>">,</cms:if>
</cms:pages>
],
eventClick: function(info) {
var dateSettings = { "year": "numeric", "month": "2-digit", "day": "2-digit"
};
var timeSettings = { "hour": "2-digit", "minute": "2-digit", "hour12": false
};
var startdate = calendar.formatDate(info.event.start, dateSettings);
var startTime = calendar.formatDate(info.event.start, timeSettings);
var enddate = calendar.formatDate(info.event.end || startdate,
dateSettings);
var endTime = calendar.formatDate(info.event.end, timeSettings);
$('#modalID').html(info.event.id);
$('#modalTitle').html(info.event.title);
$('#modalLocation').html(info.event.extendedProps.location);
$('#modalStartDate').html(startdate);
$('#modalStartTime').html(startTime);
$('#modalEndDate').html(enddate);
$('#modalEndTime').html(endTime);
$('#fullCalModal').modal();
},
eventTextColor: '#FFFFFF',
});
calendar.render();
});
</script>