1

我仍然是 JavaScript/Json 的新手(我从未使用过 Json),并且在尝试使用 DayPilot 日历时遇到了问题。(我也是法国人,请原谅我的错误)。

http://code.daypilot.org/17910/html5-event-calendar-open-source

当我下载源代码并使用它时,它工作得很好,但是当我尝试将它调整到我的数据库时,我无法让它工作。

源代码 :

<!DOCTYPE html>
    <html>
    <head>
        <title>HTML5 Event Calendar</title>
        <!-- demo stylesheet -->
            <link type="text/css" rel="stylesheet" href="media/layout.css" />    

            <link type="text/css" rel="stylesheet" href="themes/calendar_g.css" />    
            <link type="text/css" rel="stylesheet" href="themes/calendar_green.css" />    
            <link type="text/css" rel="stylesheet" href="themes/calendar_traditional.css" />    
            <link type="text/css" rel="stylesheet" href="themes/calendar_transparent.css" />    
            <link type="text/css" rel="stylesheet" href="themes/calendar_white.css" />    

        <!-- helper libraries -->
        <script src="js/jquery-1.9.1.min.js" type="text/javascript"></script>

        <!-- daypilot libraries -->
            <script src="js/daypilot/daypilot-all.min.js" type="text/javascript"></script>

    </head>
    <body>
            <div id="header">
                <div class="bg-help">
                    <div class="inBox">
                        <h1 id="logo"><a href='http://code.daypilot.org/17910/html5-event-calendar-open-source'>HTML5 Event Calendar</a></h1>
                        <p id="claim"><a href="http://javascript.daypilot.org/">DayPilot for JavaScript</a> - AJAX Calendar/Scheduling Widgets for JavaScript/HTML5/jQuery</p>
                        <hr class="hidden" />
                    </div>
                </div>
            </div>
            <div class="shadow"></div>
            <div class="hideSkipLink">
            </div>
            <div class="main">

                <div style="float:left; width: 160px;">
                    <div id="nav"></div>
                </div>
                <div style="margin-left: 160px;">
                    <div id="dp"></div>
                </div>

                <script type="text/javascript">

                    var nav = new DayPilot.Navigator("nav");
                    nav.showMonths = 3;
                    nav.skipMonths = 3;
                    nav.selectMode = "week";
                    nav.onTimeRangeSelected = function(args) {
                        dp.startDate = args.day;
                        dp.update();
                        loadEvents();
                    };
                    nav.init();

                    var dp = new DayPilot.Calendar("dp");
                    dp.viewType = "Week";

                    dp.onEventMoved = function (args) {
                        $.post("backend_move.php", 
                                {
                                    id: args.e.id(),
                                    newStart: args.newStart.toString(),
                                    newEnd: args.newEnd.toString()
                                }, 
                                function() {
                                    console.log("Moved.");
                                });
                    };

                    dp.onEventResized = function (args) {
                        $.post("backend_resize.php", 
                                {
                                    id: args.e.id(),
                                    newStart: args.newStart.toString(),
                                    newEnd: args.newEnd.toString()
                                }, 
                                function() {
                                    console.log("Resized.");
                                });
                    };

                    // event creating
                    dp.onTimeRangeSelected = function (args) {
                        var name = prompt("New event name:", "Event");
                        dp.clearSelection();
                        if (!name) return;
                        var e = new DayPilot.Event({
                            start: args.start,
                            end: args.end,
                            id: DayPilot.guid(),
                            resource: args.resource,
                            text: name
                        });
                        dp.events.add(e);

                        $.post("backend_create.php", 
                                {
                                    start: args.start.toString(),
                                    end: args.end.toString(),
                                    name: name
                                }, 
                                function() {
                                    console.log("Created.");
                                });

                    };

                    dp.onEventClick = function(args) {
                        alert("clicked: " + args.e.id());
                    };

                    dp.init();

                    loadEvents();

                    function loadEvents() {
                        var start = dp.visibleStart();
                        var end = dp.visibleEnd();

                        $.post("backend_events.php", 
                        {
                            start: start.toString(),
                            end: end.toString()
                        }, 
                        function(data) {
                            console.log(data);
                            dp.events.list = data;
                            dp.update();
                        });
                    }

                </script>

                <script type="text/javascript">
                $(document).ready(function() {
                    $("#theme").change(function(e) {
                        dp.theme = this.value;
                        dp.update();
                    });
                });  
                </script>

            </div>
            <div class="clear">
            </div>

    </body>
    </html>

和 backend_events.php :

 <?php
    require_once '_db.php'; 

    $start = '2015-02-22 00:00:00';
    $end = '2015-09-22 00:00:00';

    $stmt = $db->prepare('SELECT * FROM events WHERE NOT ((end <= :start) OR (start >= :end))');

    $stmt->bindParam(':start', $start);
    $stmt->bindParam(':end', $end);

    $stmt->execute();
    $result = $stmt->fetchAll();

    class Event {}
    $events = array();

    foreach($result as $row) {
      $e = new Event();
      $e->id = '1';
      $e->text = 'coucou';
      $e->start = '2015-05-13T10:00:00';
      $e->end = '2015-05-13T12:00:00';
      $events[] = $e;
    }


    header('Content-Type: application/json');
    echo json_encode($events);

    ?>

它将所有事件放在同一日期(它这样做是为了测试),但它有效!

当我尝试使用我的数据库修改 backend_events.php 时,事件不会出现在日历上,并且我在控制台中收到错误“无法读取未定义的属性 'getTime'”。

如您所见,我什至没有使用从数据库中获得的内容!

<?php

    // Insertion de tous les prérequis
    include '../Config/prerequis.php';
    $bdd = Donnee::getInstance()->connexion;

$start = '2015-02-22 00:00:00';
$end = '2015-09-22 00:00:00';

$stmt = $bdd->prepare('SELECT * FROM CRENEAU WHERE NOT ((Date_fin <= :start) OR (Date_debut >= :end)) AND ID_CONTRAT=16');

$stmt->bindParam(':start', $start);
$stmt->bindParam(':end', $end);

$stmt->execute();
$result = $stmt->fetchAll();


class Event {}
$events = array();

// foreach($result as $row) {
  // $e = new Event();
  // $e->id = $row['ID'];
  // $e->text = 'coucou';
  // $e->start = implode('T',explode(' ', $row['Date_debut']));
  // echo implode('T',explode(' ', $row['Date_debut'])).'<br>';
  // $e->end = implode('T',explode(' ', $row['Date_fin']));
  // $events[] = $e;
// }

foreach($result as $row) {
  $e = new Event();
  $e->id = '1';
  $e->text = 'coucou';
  $e->start = '2015-05-13T10:00:00';
  $e->end = '2015-05-13T12:00:00';
  $events[] = $e;
}


header('Content-Type: application/json');
echo json_encode($events);

?>

我已经尝试修复了几天,我什至请教了更有资格的朋友,我可以找到解决方案。因此,如果您有想法,我将不胜感激!

谢谢,海军陆战队。

4

1 回答 1

0

我们找到了解决方案。所以这是一个编码问题,

我做了一个包含'../Config/prerequis.php'; 在文件 prerequis.php 中我做了其他包含,一个我试图包含在 UTF-8 中编码的文件,而不是没有 Bom 的 UTF-8。

我现在工作得很好!

于 2015-05-13T09:03:56.250 回答