我有一个动态添加事件到日历的函数。fullCalendar - 带颜色选项的addEventSource
function AddEventSourceDetailed(act_id) {
$('#calendar').fullCalendar('addEventSource', function (start, end, callback) {
var startTime = Math.round($('#calendar').fullCalendar('getView').start.getTime()/1000);
var endTime = Math.round($('#calendar').fullCalendar('getView').end.getTime()/1000);
time = endTime - startTime;
//alert(time);
if (time <= 604800) {
$.ajax({
type: 'POST',
url: '/Employee/GetScheduleDetailedArray/',
async: false,
dataType: "json",
data: {
// our hypothetical feed requires UNIX timestamps
start: Math.round(start.getTime()/1000),
end: Math.round(end.getTime()/1000),
id: '@Model.selectedUserId',
act: act_id
},
success: function (doc) {
callback(doc);
},
error: function (xhr, status, error) {
document.appendChild(xhr.responseText);
}
}); //end ajax
} else {
callback();
}
});
}
问题是我无法弄清楚如何为这种方式添加颜色时给事件源分配颜色。
====编辑=====
好吧,我发现了一个hackish的方式来改变事件的内部背景颜色,我用的是eventAfterRender和它的元素对象比较它的列表我有颜色相关的事件。我希望这将有助于某人,直到我找到一个更好的方式
$('#calendar').fullCalendar({
height: 600,
width: 700,
header: {
right: 'prev,next today',
center: 'title',
left: 'month,agendaWeek,agendaDay'
},
eventAfterRender: function (event, element, view) {
for (x = 0; x < activityColors[0].length; x++) {
if (event.id == activityColors[0][x]) {
element.children().css({ "background-color": "#" + activityColors[1][x] })
}
}
}
});
你是正确约()我已经改变了我被导入该日历数据的方式,忘了取,走出回调。我在eventSources函数中使用它,所以它在测试时不会中断我的图表。 我会尝试添加参数到我从服务器传入的json对象。谢谢 – blackops