【问题标题】:How to use custom fields in jquery FullCalendar?如何在 jquery FullCalendar 中使用自定义字段?
【发布时间】:2017-03-27 15:21:36
【问题描述】:

我是一般的 ajax/jquery 新手,发现了 Adam Shaw 制作的 jquery 完整日历。这看起来正是我所需要的。

我找到了一些关于如何从 php/mysql 设置中读取它的教程,如果我使用他们告诉我的完全相同的字段名称(开始、结束等),它们就可以正常工作。我想知道的是如何告诉它使用我自己的日期字段作为开始和结束日期。我还想添加一些额外的字段,例如 cmets(我已经有一个日历数据库,其中包含我想要使用的数据,而无需重组它,因为其他事物使用相同的数据库)。

字段名称示例:

  • 开始日期
  • 结束日期
  • cmets
  • 重复发生

如果有人可以告诉我如何告诉它使用自定义日期字段以及显示其他很棒的自定义字段。

我目前的脚本是: 当前使用的jquery/ajax

<script>
    $(document).ready(function() {
            var date = new Date();
            var d = date.getDate(),
                m = date.getMonth(),
                y = date.getFullYear();
            $('#calendar').fullCalendar({
                header: {
                    left: 'prev,next today',
                    center: 'title',
                    right: 'month,agendaWeek,agendaDay'
                },
                buttonText: {
                    today: 'Today',
                    month: 'Month',
                    week: 'Week',
                    day: 'Day'
                },

                events: "../calendar/internal/events.php"
          });
    });
</script>

events.php

    <?php
     $json = array();
     $requete = "SELECT * FROM internal_calendar ORDER BY id";
     try {
        $bdd = new PDO('mysql:host=localhost;dbname=calendarDB', 'root', 'securepassword');
    } catch(Exception $e) {
        exit('Unable to connect to database.');
     }
     $resultat = $bdd->query($requete) or die(print_r($bdd->errorInfo()));
     echo json_encode($resultat->fetchAll(PDO::FETCH_ASSOC));

任何帮助将不胜感激。

谢谢, jAC

【问题讨论】:

    标签: php jquery mysql fullcalendar


    【解决方案1】:

    在生成结果的 json 格式之前,您需要做一些事情以使 fullcalendar 作为事件可以接受。

    $result = $resultat->fetchAll(PDO::FETCH_ASSOC);
    $events = array();
    foreach ($result as $row) {
        $events[] = array (
            'start' => date('Y-m-d H:i:s', strtotime($row['startDate'])),
            'end' => date('Y-m-d H:i:s', strtotime($row['endDate'])),
            'comments' => $row['comments'],
            'reoccuring' =>  $row['reoccuring'],
            'title' => 'Set title here', // Set comment here to show in event block.
        )
    
    }
    
    echo json_encode($events);
    

    event 的 title 属性用于在 fullcalendar 中显示事件块中的数据。您可以将 cmets 设置为标题。

    'title' => $row['comments']
    

    就是这样。

    【讨论】:

    • 这正是我想要的!非常感谢@Chintan-Mirani - 你知道我将如何公开我的 cmets 以便它们也显示在日历事件块中吗?
    • @jAc 我已编辑答案以在事件块中显示 cmets。标题属性是在事件块中显示数据。
    • 对不起,我解释得不够充分。有没有办法添加自定义字段以显示在标题下。所以仍然有标题,但 cmets 也有?
    • 您可以将标题与 cmets 合并(concat)。您还可以设置包含您的数据的自定义 html 代码。
    • 我试过了,但它没有呈现 html。例如,如果我执行
      它会显示为
      而不是新行。对此有什么想法吗?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-02-06
    • 2014-08-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多