gpt4 book ai didi

javascript - 全日历事件源不起作用

转载 作者:太空宇宙 更新时间:2023-11-04 15:31:06 24 4
gpt4 key购买 nike

SOLVED

这是我的整个ajax响应:

{
"data": [
{
"id": 3,
"calendar_id": 1,
"title": "asdasd",
"start": "2017-06-20 14:06:00",
"end": "2017-06-20 16:06:00",
"allDay": 0,
"className": "bg-green",
"deleted_at": null
}
]
}

定义:

$('#calendar').fullCalendar({
slotDuration: //..
minTime: //...
maxTime: //..
defaultView: //...
defaultDate: //..
header: {
//...
},
eventSources: [
{
url: '/api/calendar_events/' + id,
type: 'GET',
headers: {
'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
},
error: function () {
alert('there was an error while fetching events!');
}
}
],
eventLimit: //..
selectable: //..
});

EventSources 出了什么问题?呈现完整日历,但不显示任何事件。

注意:我想使用 eventSource 而不是事件,因为可能有多个源。

最佳答案

这样做了:

eventSources: [
{
events: function (start, end, timezone, callback) {
$.ajax({
url: '/api/calendar_events/' + id,
type: 'GET',
headers: {
'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
}, success: function (response) {
var events = [];
$(response['data']).each(function () {
events.push({
id: $(this).attr('id'),
title: $(this).attr('title'),
start: $(this).attr('start'),
end: $(this).attr('end'),
className: $(this).attr('className'),
allDay : $(this).attr('allDay'),
});
});
callback(events);
}
});
}
}
],

关于javascript - 全日历事件源不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44781522/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com