doufangyan6862 2010-05-18 19:42
浏览 202
已采纳

FullCalendar不显示JSON事件的时间

Greetings,

Using FullCalendar (http://arshaw.com/fullcalendar/) to pull events from a MySQL database table via JSON. The events are being displayed in the calendar but for some reason it is ignoring the time (hours, minutes, seconds) of the event. Here is the Javascript from the calendar page -

<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
' +
                    '(should probably update your database)');
            },

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

        });

    });

</script>

and my JSON PHP file (note that I am including the time after the date, presently that field is set as DATE only):

<?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);
?>

The above outputs:

[{"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"}]

Thanks!

Edit

Here is the modified PHP to reflect the accepted solution. Thanks!

    <?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);
?>
  • 写回答

3条回答 默认 最新

  • douxi2670 2010-06-10 19:47
    关注

    Try adding 'allDay': false to your json. I had the same issue, see 'allDay' documentation specifically:

    Don't include quotes around your true/false. This value is not a string!

    When specifying Event Objects for events or eventSources, omitting this property will make it inherit from allDayDefault, which is normally false.

    However, 'allDayDefault' defaults to true?!?

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

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

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥100 c语言,请帮蒟蒻写一个题的范例作参考
  • ¥15 名为“Product”的列已属于此 DataTable
  • ¥15 安卓adb backup备份应用数据失败
  • ¥15 eclipse运行项目时遇到的问题
  • ¥15 关于#c##的问题:最近需要用CAT工具Trados进行一些开发
  • ¥15 南大pa1 小游戏没有界面,并且报了如下错误,尝试过换显卡驱动,但是好像不行
  • ¥15 没有证书,nginx怎么反向代理到只能接受https的公网网站
  • ¥50 成都蓉城足球俱乐部小程序抢票
  • ¥15 yolov7训练自己的数据集
  • ¥15 esp8266与51单片机连接问题(标签-单片机|关键词-串口)(相关搜索:51单片机|单片机|测试代码)