[英]fullCalendar - addEventSource with the color option
我有一個將事件動態添加到日歷的功能。
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();
}
});
}
問題是當以這種方式添加顏色時,我無法弄清楚如何為事件源分配顏色。
====編輯=====
好的,我發現了一種改變事件內部背景顏色的方法,我使用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] })
}
}
}
});
您可以使用:
$('#calendar').fullCalendar( 'addEventSource', {
url: "/url/goes/here",
color: '#05ABBD'
});
在您的函數中,ajax調用的結果是什么? 根據您代碼中的內容(success:function(doc){callback(doc);}),我想成功時您會收到用json編碼的事件數組,因此,您唯一需要添加顏色的就是定義字段color,服務器端腳本中每個事件的backgroundColor,borderColor,textColor。 希望這可以幫助。
一月
編輯:我還注意到您在else分支中調用callback()函數,這確實是多余的。 沒有參數,調用回調是毫無意義的,因為它什么都不做(callbacks參數是要添加到fullcalendar的事件數組,因此沒有參數=沒有要添加的事件=甚至沒有被調用)。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.