我有一個動態添加事件到日曆的函數。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