简体   繁体   English

模态弹出窗口中的全日历事件信息

[英]fullcalendar event info in modal popup

I am working on fullCalendar and attempting to get the event info to show in a popup modal (when the event is clicked on). 我正在研究fullCalendar,并尝试获取事件信息以在弹出模式中显示(单击事件时)。

However I can only get the event title, location, start date and end date showing. 但是,我只能显示事件的标题,位置,开始日期和结束日期。

I also need the start time and end time showing. 我还需要显示开始时间和结束时间。 What am I doing wrong? 我究竟做错了什么?

My code is below: 我的代码如下:

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();
},

My updated code is below 我的更新代码如下

 <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>

You are really tying yourself in knots here. 您真的在这里打结。

1) As per the documentation event.start and event.end are already Date objects. 1)根据文档 event.startevent.end已经是Date对象。 There is really no need to parse them into another Date or make them into MomentJS objects again. 确实没有必要将它们解析为另一个Date或再次使它们成为MomentJS对象。 Just use them as they already are, and format them as needed using fullCalendar's provided date formatting functionality . 只需按原样使用它们,然后使用fullCalendar提供的日期格式化功能根据需要对其进行格式化

2) The event object (again see docs above) does not have a separate "startTime" or "endTime" property...the whole date and time is stored within start and end . 2)事件对象(再次参见上面的文档)没有单独的“ startTime”或“ endTime”属性...整个日期和时间存储在startend I'm not sure where you got the idea that separate properties exist? 我不确定您是否知道存在单独的属性? This has never been the case in any version of fullCalendar. 在任何版本的fullCalendar中,从未如此。

3) You need to deal with the case where the event's end property might be null, so there's a little bit of extra logic to handle that, and just use the start date/time instead: 3)您需要处理事件的end属性可能为null的情况,因此需要处理一些额外的逻辑,而只需使用开始日期/时间即可:

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; 
  var endtime; 
  if (info.event.end != null) {
    enddate = calendar.formatDate(info.event.end, timeSettings );
    endtime = calendar.formatDate(info.event.end, dateSettings );
  } 
  else {
    enddate = startdate;
    endtime = starttime;
  }

  $('#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();
},

Demo: https://codepen.io/anon/pen/eapjWN?editors=1010 演示: https//codepen.io/anon/pen/eapjWN?editors = 1010

NB If, as it appears, you are using fullCalendar v4, then your callback arguments for eventClick are wrong - again see the relevant documentation - yours look like the v3 arguments. 注意:如果您似乎正在使用fullCalendar v4,则eventClick的回调参数是错误的-再次参见相关文档 -您的外观类似于v3参数。 jsEvent and view are no longer supplied separately, instead they are supplied within the info object which is now the first argument. jsEventview不再分开提供,而是在info对象(现在是第一个参数)中提供。 And talking of that, calling the first argument event is really a misnomer, since it contains more than that. 谈到这一点,调用第一个参数event确实是一个错误的称呼,因为它包含的内容不止于此。 The fact you've ended up writing event.event... tells you you've got a naming problem. 您最终写了event.event...的事实event.event...您遇到了命名问题。 Better to name it more meaningfully. 最好命名得更有意义。 In the interest of code quality, my example above makes those changes in addition to the ones necessary to solve the actual problem. 为了代码质量,我上面的示例除了解决实际问题所需的更改之外,还进行了这些更改。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM