FullCalendar不显示来自JSON事件的时间 [英] FullCalendar not displaying time from JSON events

查看:153
本文介绍了FullCalendar不显示来自JSON事件的时间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

问候,

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

 < script type ='text / javascript'> 
$ b $(文档).ready(函数(){

$('#calendar')。fullCalendar({

editable:false,

events:json-events.php,

eventDrop:function(event,delta){
alert(event.title +'was moved'+ delta +'days'\
'+
'(应该更新数据库)');
},

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:测试2,开始:2010-06-18 13:00:00,结束: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, 称号: TEST4, 开始:2010-05 -03 13:00:00,end:0000-00-00 14:00:00,url:http:\ / \ / somewhere.org}] 

谢谢!
$ b 编辑



以下是修改的PHP以反映可接受的解决方案。

 <?php 
包括$ _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。 。 $行[时间];
$ eventsArray ['end'] = $ end;
$ eventsArray ['url'] =#;
$ eventsArray ['allDay'] = false;
$ events [] = $ eventsArray;
}


echo json_encode($ events);
?>


解决方案

尝试向您的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/


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\n' +
                    '(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);
?>

解决方案

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/

这篇关于FullCalendar不显示来自JSON事件的时间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆