Cảm ơn bạn cho ví dụ này :)
tôi đã không thể thực hiện điều này (trong mã trên mảng sự kiện) làm việc cho tôi, nhưng tôi tìm ra một cách khác để thêm nguồn sự kiện sử dụng một số mã bạn được cung cấp.
Đây là logic của tôi:
nguồn chủ yếu của tôi về sự kiện này (đây là nguồn sự kiện từ các ví dụ mặc định của Fullcalendar):
events: function(start, end, callback) {
$.ajax({
type: 'POST',
url: 'myurl',
dataType:'xml',
crossDomain: true,
data: {
// our hypothetical feed requires UNIX timestamps
start: Math.round(start.getTime()/1000),
end: Math.round(end.getTime()/1000),
'acc':'2',
},
success: function(doc) {
var events = [];
var allday = null; //Workaround
var Editable = null; //Workaround
$(doc).find('event').each(function()
{
if($(this).attr('allDay') == "false") //Workaround
allday = false; //Workaround
if($(this).attr('allDay') == "true") //Workaround
allday = true; //Workaround
if($(this).attr('editable') == "false") //Workaround
Editable = false; //Workaround
if($(this).attr('editable') == "true") //Workaround
Editable = true; //Workaround
events.push({
id: $(this).attr('id'),
title: $(this).attr('title'),
start: $(this).attr('start'),
end: $(this).attr('end'),
allDay: allday,
editable: Editable
});
});
//calendar.fullCalendar('addEventSource', othersources.folgas);
//calendar.fullCalendar('addEventSource', othersources.ferias);
//calendar.fullCalendar('refetchEvents');
callback(events);
}
});
}
Bây giờ tôi cần nó để thêm các nguồn khác và để làm điều này ở bên lịch (bên cạnh biến ngày từ ví dụ đầy đủ) tôi đã tạo một biến như mã ở trên, nhưng với các cuộc gọi ajax tương tự như mã chính của tôi:)
var othersources = {
anothersource: {
events: function(start, end, callback) {
$.ajax({
type: 'POST',
url: 'myurl',
data: {
// our hypothetical feed requires UNIX timestamps
start: Math.round(start.getTime()/1000),
end: Math.round(end.getTime()/1000),
'acc':'7',
},
success: function(doc) {
var events = [];
var allday = null; //Workaround
var Editable = null; //Workaround
$(doc).find('event').each(function()
{
if($(this).attr('allDay') == "false") //Workaround
allday = false; //Workaround
if($(this).attr('allDay') == "true") //Workaround
allday = true; //Workaround
if($(this).attr('editable') == "false") //Workaround
Editable = false; //Workaround
if($(this).attr('editable') == "true") //Workaround
Editable = true; //Workaround
events.push({
id: $(this).attr('id'),
title: $(this).attr('title'),
start: $(this).attr('start'),
end: $(this).attr('end'),
allDay: allday,
editable: Editable
});
});
callback(events); //notice this
}
});
},
cache: true,
//error: function() { alert('something broke with courses...'); },
color: 'green', //events color and stuff
textColor: 'white',
//className: 'course'
}
}
Các mã sau đây là tương tự như trên và là một phần của proprietys lịch (bên trong biến lịch):
eventSources: [ othersources.anothersource ],
viewDisplay: function(view) {
if (view.name == 'month'){
// alert(view.name);
//calendar.fullCalendar('addEventSource', othersources.folgas);
calendar.fullCalendar('addEventSource', othersources.anothersource);
//calendar.fullCalendar('refetchEvents'); //Notice i'm not doing the refetch events. And its working for me. but i'm calling thi elsewhere, every time i make an action. So you must figure it out ;)
}
cảm ơn câu trả lời. Với mã của bạn, tôi đã có thể đưa ra các thông tin sau: $ ("# TaskSelector"). Change (onSelectChange); \t chức năng onSelectChange() { \t \t $ ('# calendar'). FullCalendar ('removeEventSource', root + '/ events /' + defaultFeed) .fullCalendar ('refetchEvents'); \t \t defaultFeed = $ ('# TaskSelector'). Val(); \t \t $ ('# calendar'). FullCalendar ('addEventSource', root + '/ events /' + defaultFeed) .fullCalendar ('refetchEvents'); \t} }); Nó hoạt động tốt, nhưng bạn có thể thấy bất kỳ vấn đề với nó? Tôi đặt defaultFeed ở đầu mã, và cho đến nay rất tốt. Cảm ơn bạn đã trả lời! – Kingsley
@RET http://stackoverflow.com/questions/37204410/how-to-show-event-details-on-click-of-day-in-full-calendar bạn có thể vui lòng kiểm tra câu hỏi này không? –