我在CodeIgniter应用程序中使用FullCalendar插件。我使用GET请求服务器端检索事件对象,事件不显示在日历上,使用与事件作为回调函数示例类似的方法。我已经验证了GET请求正确返回json。
这是我的请求返回的json…
[{"id":"1","title":"2011 Acura Integra (1)","start":1313996400,"color":"red"}, {"id":"15","title":"2011 Acura Integra (1)","start":1314774000,"color":"red"}]
我的电话如下…
var year = $("#year").text();
var month = $("#month").text();
$maintenance_schedule_calendar_table = $("#vehicles_maintenance_schedule_calendar").fullCalendar({
year: year,
month: month -1,
header: {
left: 'prev,next today',
center: 'title',
right: ''
},
editable: true,
disableResizing: true,
events: function(start, end, callback) {
var start_timestamp = Math.round(start.getTime() / 1000);
var end_timestamp = Math.round(end.getTime() / 1000);
var url = "/tripsys/new_admin/vehicles/get_maintenance_schedule_data/" + start_timestamp + "/" + end_timestamp;
$.get(url, function(events) {
callback(events);
});
}
});
奇怪的是,之前的调用正确地获取json,回调似乎处理事件,因为如果我调用。fullcalendar (' clienttevents ')它显示了我传递到事件方法的json,但它们不呈现。
然而,如果我传递相同的json到我的初始FullCalendar调用直接事件渲染…
var year = $("#year").text();
var month = $("#month").text();
$maintenance_schedule_calendar_table = $("#vehicles_maintenance_schedule_calendar").fullCalendar({
year: year,
month: month -1,
header: {
left: 'prev,next today',
center: 'title',
right: ''
},
editable: true,
disableResizing: true,
events: [
{"id":"1","title":"2011 Acura Integra (1)","start":1313996400,"color":"red"},
{"id":"15","title":"2011 Acura Integra (1)","start":1314774000,"color":"red"}
]
});
有没有人知道为什么第一个例子没有渲染我的日历上的事件?
问题是由于我用$请求数据引起的。get而不是$.getJSON
这是正确的呼叫…
var year = $("#year").text();
var month = $("#month").text();
$maintenance_schedule_calendar_table = $("#vehicles_maintenance_schedule_calendar").fullCalendar({
year: year,
month: month -1,
header: {
left: 'prev,next today',
center: 'title',
right: ''
},
editable: true,
disableResizing: true,
events: function(start, end, callback) {
var start_timestamp = Math.round(start.getTime() / 1000);
var end_timestamp = Math.round(end.getTime() / 1000);
var url = "/tripsys/new_admin/vehicles/get_maintenance_schedule_data/" + start_timestamp + "/" + end_timestamp;
$.getJSON(url, function(events) {
callback(events);
});
}
});