我正在创建一个调度Web应用程序,我正在尝试从我的SQL数据库加载我的资源。它显示它正在运行我的php文件来检索资源,但它们都没有显示在日历上。我不确定他们为什么没有出现,我查看了fullcalendar的文档,在我看来,我正在遵守规则。谁知道为什么?
以下是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);
}
?>
答案 0 :(得分: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。
我希望这可以帮助您调试问题。对不起,我可以给你一个直接的答案。