我知道有一些如何使用FullCalendar使用多个Feed源的示例,即: Stackoverflow post
但是,它们都没有显示如何使用多个Feed源以及类型,数据等其他ajax信息。
我正在尝试使用多个Feed源但无法使其工作。这是我的代码:
eventSources: [
'json-schedule.php',
'json-events.php'
],
type: 'POST',
data: {
// custom_param1: 'something',
},
error: function() {
alert('there was an error while fetching events!');
},
success: function() {
},
类型,数据,错误和放大器在哪里?成功部分与多个数据源一起使用?我发现的所有例子都没有显示出来。
答案 0 :(得分:2)
尝试这种方式:
$('#calendar').fullCalendar({
...
eventSources: [
// your JSON event source
{
url: '/myfeed.php', // use the `url` property
color: 'yellow', // an option!
textColor: 'black' // an option!
},
// your ajax event source
{
events: function(start, end, callback) {
$.ajax({
url: 'myxmlfeed.php',
dataType: 'xml',
data: {
// our hypothetical feed requires UNIX timestamps
start: Math.round(start.getTime() / 1000),
end: Math.round(end.getTime() / 1000)
},
success: function(doc) {
var events = [];
$(doc).find('event').each(function() {
events.push({
title: $(this).attr('title'),
start: $(this).attr('start') // will be parsed
});
}
});
}
}
],
...
});
答案 1 :(得分:1)
eventSources: [
{
url: 'json-schedule.php',
type: 'POST',
data: {
date: start, //data to be sent
custom_param2: 'somethingelse'
},
error: function() {
alert('there was an error while fetching shedule!');
},
color: 'yellow', // a non-ajax option
textColor: 'black' // a non-ajax option
},
{
url: 'json-events.php',
type: 'POST',
/*data: {
custom_param1: 'something',
custom_param2: 'somethingelse'
},*/
error: function () {
alert('there was an error while fetching events!');
},
color: 'green', // a non-ajax option
textColor: 'black' // a non-ajax option
}
],
答案 2 :(得分:0)
我的方法与添加多个事件源有些不同,但是效果很好。
var fcSources = {
loadEvents: {
url: "/get-all-events-from-mysql",
type: "GET",
color: "#65a9d7",
textColor: "#3c3d3d",
cache: true,
className: "events",
data:
{
start: "start",
end: "end",
id: "id",
title: "title"
},
error: function() {
console.log("Error in loadEvents: " + data);
},
},
loadEwsEvents: {
url: "/get-ews-events",
type: "GET",
color: "#FF6347",
textColor: "#000000",
cache: true,
editable: false,
disableDragging: true,
className: "events",
data: {
start: "start",
end: "end",
id: "id",
title: "title"
},
error: function() {
console.log("Error in loadEWSEvents: " + data);
},
}
};
//在fullcalendar函数中添加这些来源
eventSources: [
fcSources.loadEvents,
fcSources.loadEwsEvents
],