-2

我正在创建一个调度 Web 应用程序,并尝试从我的 SQL 数据库加载我的资源。它显示它正在运行我的 php 文件来检索资源,但它们都没有显示在日历上。我不太确定他们为什么不显示,我查看了 fullcalendar 的文档,在我看来,我正在遵守规则。有谁知道为什么?

这是完整日历的代码:

   var calendar = $('#calendar').fullCalendar({
    schedulerLicenseKey: 'GPL-My-Project-Is-Open-Source',
    header:{
      left:'promptResource, prev, next, today',
      center:'title',
      right: 'month, agendaDay, timelineThreeDays, listDay'
    },
    views: {
      timelineThreeDays: {
        type: 'timeline',
        duration: { days: 3 },
        slotWidth: 75,
      }
    },
    businessHours: {
      dow: [1, 2, 3, 4, 5],
      start: "09:00",
      end: "17:00",
    },
    resources: "resourceGetScript.php",
    events: [
      { id: '1', resourceId: '1', start: '2017-04-05T10:00:00', end: '2017-04-05T11:00:00', title: 'event 1', doctor: 'Habib Habib'},
    ],
    defaultView: "timelineDay",
    minTime: "09:00",
    maxTime: "17:00",
    weekends: false,
    slotDuration: "01:00:00",
    allDaySlot: false,
    selectable: true,
    theme: true,
    contentHeight: 800,
    eventOverlap: false,
    resourceAreaWidth: "12%",
    slotWidth: 200,
    resourceLabelText: 'Rooms',
    select: function(start, end, allDay, jsEvent, view) {
      alert("test");
    },
    eventClick: function(calEvent, jsEvent, view){
      var myResource = calendar.fullCalendar('getEventResource', calEvent);
      myResource.title = "Change";
      calendar.fullCalendar('refetchResources');
      alert('Event: ' + calEvent.title + " " + calEvent.resourceId + " " + myResource.title);
    },
    resourceRender: function(resourceObj, labelTds, bodyTds){
      labelTds.on('click', function(){alert("clicked" + resourceObj.id + resourceObj.title);});
    }
  })

这是resourceGetScript.php的代码,我从数据库中检索资源:

<?php
  session_start();
  include("includes/databaseHandler.inc.php");
  if(!isset($_SESSION['name'])){
    header("Location: ../index.php");
  }

  if($stmt = mysqli_prepare($conn, "SELECT * FROM rooms")){
    mysqli_stmt_execute($stmt);
    $result = mysqli_stmt_get_result($stmt);
    $resources = array();
    while ($row = mysqli_fetch_assoc($result)){
      $resourceArray['id'] = $row['id'];
      $resourceArray['title'] = $row['title'];
      $resources[] = $resourceArray;
    }

    echo json_encode($resources);
  }
 ?>
4

1 回答 1

0

没有充分使用 FullCalendar 的资源功能。但是为了消除这个问题,首先尝试使用这个文档对一些资源进行硬编码:https ://fullcalendar.io/docs/resource_data/resources_array/ 。

您可以使用此演示手动构建资源并测试您的 PHP 文件:https ://github.com/StarterSquad/fullcalendar-resource/blob/master/demos/json-resource-events.php 。

如果它工作正常,请在jscon_encode($resources)之前运行resourceGetScript.php文件和print_r($ resources)以确保您已正确构建资源。还可以使用mb_detect_encoding()检查文本的格式,如果需要,使用 mb_convert_encoding() 转换为 UTF- 8

我希望这可以帮助您调试问题。对不起,我可以给你一个直接的答案。

于 2017-04-06T13:13:50.897 回答