6

使用 FullCalendar ( http://arshaw.com/fullcalendar/ ) 通过 JSON 从 MySQL 数据库表中提取事件。事件显示在日历中,但由于某种原因,它忽略了事件的时间(小时、分钟、秒)。这是日历页面中的 Javascript -

<script type='text/javascript'>
$(document).ready(function() {
  $('#calendar').fullCalendar({
    editable: false,
    events: "json-events.php",

    eventDrop: function(event, delta) {
      alert(event.title + ' was moved ' + delta + ' days\n' +
        '(should probably update your database)');
    },

    loading: function(bool) {
      if (bool) $('#loading').show();
      else $('#loading').hide();
    }
  });
});
</script>

和我的 JSON PHP 文件(请注意,我包括日期之后的时间,目前该字段仅设置为 DATE):

<?php
include $_SERVER['DOCUMENT_ROOT'] . '/includes/pdo_conn.inc.php';
$getEventsSQL = $db->query("SELECT id, title, date_start AS start, date_end AS end FROM training");

$events = array();
while ($row = $getEventsSQL->fetch()) {
    $start = $row['start'];
    $end = $row['end'];
    $title = $row['title'];
    $eventsArray['id'] =  $row['id'];
    $eventsArray['title'] = $title;
    $eventsArray['start'] = $start . " 13:00:00";
    $eventsArray['end'] = $end . " 14:00:00";
    $eventsArray['url'] = "http://somewhere.org";
    $events[] = $eventsArray;
}


echo json_encode($events);
?>

上述输出:

[{
  "id": "13",
  "title": "Test 1",
  "start": "2010-05-18 13:00:00",
  "end": "0000-00-00 14:00:00",
  "url": "http:\/\/tapp-essexvfd.org"
}, {
  "id": "14",
  "title": "Test 2",
  "start": "2010-06-18 13:00:00",
  "end": "2010-06-19 14:00:00",
  "url": "http:\/\/tapp-essexvfd.org"
}, {
  "id": "15",
  "title": "Test 3",
  "start": "2010-06-18 13:00:00",
  "end": "0000-00-00 14:00:00",
  "url": "http:\/\/somewhere.org"
}, {
  "id": "16",
  "title": "test4",
  "start": "2010-05-03 13:00:00",
  "end": "0000-00-00 14:00:00",
  "url": "http:\/\/somewhere.org"
}]

谢谢!

编辑

这是修改后的 PHP 以反映公认的解决方案。谢谢!

    <?php
include $_SERVER['DOCUMENT_ROOT'] . '/includes/pdo_conn.inc.php';
$getEventsSQL = $db->query("SELECT id, title, date_start AS start, time FROM events WHERE date_start >= NOW() AND status = 1");

$events = array();
while ($row = $getEventsSQL->fetch()) {
    $start = $row['start'];
    $title = $row['title'];
    $eventsArray['id'] =  $row['id'];
    $eventsArray['title'] = $title;
    $eventsArray['start'] = $start . " " . $row['time'];
    $eventsArray['end'] = $end;
    $eventsArray['url'] = "#";
    $eventsArray['allDay'] = false;
    $events[] = $eventsArray;
}


echo json_encode($events);
?>
4

3 回答 3

12

尝试将 'allDay': false 添加到您的 json 中。我遇到了同样的问题,具体参见“allDay”文档:

不要在你的真/假周围加上引号。该值不是字符串!

当为事件或事件源指定事件对象时,省略此属性将使其继承自 allDayDefault,通常为 false。

但是,“allDayDefault”默认为真?!?

http://arshaw.com/fullcalendar/docs/event_data/Event_Object/

http://arshaw.com/fullcalendar/docs/event_data/allDayDefault/

于 2010-06-10T19:47:54.453 回答
1

您可以在创建日历时设置allDayDefault为:false

$('#calendar').fullCalendar({
   allDayDefault: false,
   event: ...
});
于 2013-06-10T13:46:48.643 回答
-1

日期中的破折号无效。代替:

[{"id":"10", "title":"Urlaub", "start":"2010-11-24T07:30:00+01:00", 
  "end":"2010-11-24T16:15:00+01:00", "allDay":false}]

应该:

[{"id":"10", "title":"Urlaub", "start":"2010 11 24 07:30:00+01:00",
  "end":"2010 11 24 16:15:00+01:00", "allDay":false}]
于 2011-12-22T04:57:06.370 回答