2010-05-18 138 views
6

問候,FullCalendar不是從JSON事件顯示時間

使用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文件(注意,我包括時間日期後,目前該字段設置爲僅日期):

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

感謝分享它幫助我感謝 – Devjosh 2011-10-20 13:49:45

+0

夜晚的問題,是否有可能給我一個你的數據庫的快照,看看我應該如何根據你的代碼來設計它。 – 2012-04-17 02:59:48

回答

12

試着給你的json添加'allDay':false。我有同樣的問題,具體請參閱'allDay'文檔:

請勿在您的真/假附加引號。這個值不是一個字符串!

當爲事件或事件源指定事件對象時,省略此屬性將使其繼承自allDayDefault,通常爲false。

但是,'allDayDefault'默認爲true?!?

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

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

+0

謝謝,這是訣竅!對不起,接受你的解決方案花了這麼長時間,一直在旁邊。如果您有興趣,請參閱修改後的PHP的編輯。 :) – NightMICU 2010-06-19 22:21:24

+0

@感謝Jared Knipp它真的救了我bwoooh! – Devjosh 2011-10-20 13:49:13

+0

兩年半之後,您的評論解決了我的問題。也就是說,'真'假'不是字符串。謝謝 :) – Garfonzo 2013-01-08 18:11:54

-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}] 
1

您可以設置allDayDefaultfalse創建日曆時:

$('#calendar').fullCalendar({ 
    allDayDefault: false, 
    event: ... 
}); 
相關問題