使用"events"上的函数,我不能显示我的事件,但如果我使用在控制台中使用相同返回变量的console.log生成的字符串,我可以显示我的活动。为什么?
$(document).ready(function () {
var date = new Date();
var d = date.getDate();
var m = date.getMonth();
var y = date.getFullYear();
// page is now ready, initialize the calendar...
var calendar = $('#calendar');
calendar.fullCalendar({
// put your options and callbacks here
'theme': false,
'header': {
left: 'prev,next today',
center: 'title',
right: 'month,agendaWeek,agendaDay'
},
'weekends': false,
'defaultView': 'agendaDay',
axisFormat: 'HH:mm',
timeFormat: {
// for agendaWeek and agendaDay
agenda: 'H:mm{ - H:mm}', // 5:00 - 6:30
// for all other views
'': 'H(:mm)t' // 7p
},
minTime: 8,
ignoreTimezone: true,
editable: true,
selectable: true,
selectHelper: true,
select: function (startDate, endDate, allDay, jsEvent, view) {
/*
after selection user will be promted for enter title for event.
*/
var title = prompt('Event Title:');
/*
if title is enterd calendar will add title and event into fullCalendar.
*/
if (title) {
calendar.fullCalendar('renderEvent',
{
title: title,
start: startDate,
end: endDate,
allDay: allDay
},
true // make the event "stick"
);
}
calendar.fullCalendar('unselect');
},
eventDrop: function (event, delta) {
alert(event.title + ' was moved ' + delta + ' daysn' +
'(should probably update your database)');
},
events: function getjson() {
var out;
$.ajax({
url: 'http://localhost:8000/calendar/api/events/events/',
type: 'GET',
async: false,
success: function (data) {
out = JSON.stringify(data['objects']);
},
error: function () {
alert('errore');
}
});
console.log('hshshshshsh', out);
return out;
}
我使用的json资源显示事件对象
您可以直接输入URL(如下所述):
calendar.fullCalendar({
events: 'http://localhost:8000/calendar/api/events/events/'
});
以下代码对我很有用。它可能会发现你很有用。。只需根据您的代码进行更改
events: function (start, end, callback) {
$.ajax({
type: "POST",
contentType: "application/json; charset=utf-8",
url: "Put your url here",
dataType: "json", // datatype returned by the webservice
success: function (data) {
var events = $.map(data.d, function (item, i) {
var event = new Object();
event.id = item.id;
event.start = new Date(item.date);
event.title = item.title;
event.color = item.color;
return event;
});
callback(events);
}, //end of Success function
error: function (XMLHttpRequest, textStatus, errorThrown) {
alert("StatusEvents: " + textStatus);
alert("Error: " + errorThrown);
}
}); //end of Ajax Function
} //end of events function
我的json实体就像
[Serializable]
public class Events
{
public int id { get; set; }
public string title { get; set; }
public DateTime date { get; set; }
public string color { get; set; }
}