我正在尝试制作一个显示所有工作日和事件的日历,而不考虑它是每月的哪一天。来自数据库的日期是“随机”的,在 C# 代码中,我获取当前星期并将每个“随机”日期与当前星期的相应日期相关联(因此用户不会)(public DateTime AssimilarDataAoDiaSemana(string dia,列出 dts))。
我有这个 C# 代码 https://pastebin.com/ipe4t8Pa ,返回一个JSON,例如:
{
"events":[
{
"title": "VIP",
"start": "2018-03-03 10:00:00",
"end": "2018-03-03 11:00:00",
"allDay": false
},
{
"title": "ALMANAQUE DA CACAU",
"start": "2018-02-25 17:00:00",
"end": "2018-02-25 18:00:00",
"allDay": false
}
]
}
这是我的 JavaScript
function Grade() {
if (VerificarURL("programacao")) {
var cal = $("#calendario").fullCalendar({
events: {
url: "/programacao/calendario",
dataType: "json",
type: "GET",
success: function (data) {
console.log(data);
},
color: "white",
textColor: 'white'
},
columnHeaderFormat: "dddd",
handleWindowResize: true,
header: false,
height: "auto",
defaultView: "agendaWeek",
editable: false,
minTime: "06:00",
maxTime: "24:00",
displayEventTime: false,
allDaySlot: false,
allDayText: false,
timeFormat: "HH(:mm)",
slotLabelFormat: "HH:mm",
});
}
}
问题是:事件未在客户端中呈现。有什么想法吗?
最佳答案
很简单,您返回的 JSON 格式与 fullCalendar 期望的格式不兼容。您只需返回事件数组,而不需要将对象包裹在其周围。您的事件数据只需如下所示:
[
{
"title": "VIP",
"start": "2018-03-03 10:00:00",
"end": "2018-03-03 11:00:00",
"allDay": false
},
{
"title": "ALMANAQUE DA CACAU",
"start": "2018-02-25 17:00:00",
"end": "2018-02-25 18:00:00",
"allDay": false
}
]
fullCalendar 期望 JSON 是一个数组。如果您按照示例返回一个对象,它不知道在其中查找数组,并且只会假设没有事件。
如果您稍微修改 C# 代码来生成此输出,它应该可以很好地工作。
关于javascript - Fullcalendar 不在客户端呈现事件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49038437/