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);
?>
dsfjk44656
dsfjk44656 晚上,是否可以给我一个数据库快照,看看我应该如何根据你的代码设计它。
8 年多之前 回复
dongyuans61046
dongyuans61046 感谢分享它帮助我的问题
接近 9 年之前 回复

3个回答



尝试将“allDay”:false添加到您的json中。 我有同样的问题,具体请参阅'allDay'文档:</ p>


不要在true / false附近加引号。 此值不是字符串!</ p>

为事件或eventSources指定事件对象时,省略此属性将使其继承自allDayDefault,通常为false。</ em> </ strong> </ p>
</ blockquote>

但是,'allDayDefault'默认为true?!?</ p>

http://arshaw.com/fullcalendar/docs/event_data/Event_Object/ </ p>
\ n

http://arshaw.com/fullcalendar/docs/event_data/allDayDefault/</ a> </ p>
</ div>

展开原文

原文

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/

doulan2827
doulan2827 两年半之后,你的评论解决了我的问题。 即,True False不是字符串的事实。 谢谢 :)
7 年多之前 回复
duanqian2278
duanqian2278 Jared Knipp真的救了我bwoooh !!!
接近 9 年之前 回复
dsbc80836
dsbc80836 谢谢,这就是诀窍! 对不起,接受你的解决方案需要很长时间,因此受到了挫折。 如果您有兴趣,请参阅我修改过的PHP的编辑。 :)
大约 10 年之前 回复



您可以在创建日历时将 allDayDefault </ code>设置为 false </ code>:</ p>

  $('#calendar')。fullCalendar({
allDayDefault:false,
event:...
});
</ code> </ pre >
</ div>

展开原文

原文

You can set the allDayDefault as false when creating the calendar:

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



日期中的破折号无效。 而不是:</ p>

  [{“id”:“10”,“title”:“Urlaub”,“start”:“2010-11-24T07:30:00+  01:00“,
”结束“:”2010-11-24T16:15:00 + 01:00“,”allDay“:false}]
</ code> </ pre>

应该是:</ p>

  [{“id”:“10”,“title”:“Urlaub”,“start”:“2010 11 24 07:30:00+  01:00“,
”end“:”2010 11 24 16:15:00 + 01:00“,”allDay“:false}]
</ code> </ pre>
</ div>

展开原文

原文

Dashes in dates are not valid. Instead of:

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

Should be:

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

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问
相关内容推荐