Tôi cần chạy một số mã javascript để tải lại lịch khi người dùng nhấp vào, các nút ngày/tuần/tháng. Có bất kỳ callback như dayButtonClicked() hoặc một cái gì đó?gọi lại cho các nhấp chuột vào nút thanh tiêu đề của tháng, tuần, ngày?
BUG xảy ra:
khi lần đầu tiên tải lịch. Cái nhìn ban đầu trông đẹp mỏ ban đầu tải ngày. Ngay sau khi tôi tải một chế độ xem khác như tuần. Mỗi mục duy nhất được sao chép và hiển thị cả hai nguồn dữ liệu. Nếu sau đó tôi nhấp lại và chuyển tiếp giữa ngày và tháng một lần nữa, dữ liệu sẽ trở lại bình thường. Điều gì đang xảy ra là removeEventSource không được gọi khi lần đầu tiên tải chế độ xem mới sau khi nhấp từ ngày này sang tuần khác. bạn đã thấy điều này xảy ra trước đây chưa?
<script type='text/javascript'>
$(document).ready(function() {
var date = new Date();
var d = date.getDate();
var m = date.getMonth();
var y = date.getFullYear();
var loadUrl = "menu_booking.php?ne=1&calsub=1";
var lastView;
var fullSource = "../fullcalendar/json-events.php?idc=<?= $sClient ?>&v=long";
var liteSource = "../fullcalendar/json-events.php?idc=<?= $sClient ?>";
$('#calendar').fullCalendar({
header: {
left: 'prev,next today',
center: 'title',
right: 'month,agendaWeek,agendaDay'
},
columnFormat: {
month: 'ddd',
week: 'ddd d/M',
day: 'dddd d/M'
},
defaultView: 'agendaDay',
firstDay: 1,
//editable: true,
selectable: true,
allDaySlot: false,
firstHour: 7,
viewDisplay: function(view) {
if (lastView == undefined) { lastView = 'firstRun'; }
if (view.name != lastView) {
if (view.name == 'agendaWeek') {
$('#calendar').fullCalendar('removeEventSource', fullSource);
$('#calendar').fullCalendar('removeEventSource', liteSource);
$('#calendar').fullCalendar('addEventSource', fullSource);
}
if (view.name == 'agendaDay') {
$('#calendar').fullCalendar('removeEventSource', fullSource);
$('#calendar').fullCalendar('removeEventSource', liteSource);
$('#calendar').fullCalendar('addEventSource', liteSource);
}
if (view.name == 'month') {
$('#calendar').fullCalendar('removeEventSource', fullSource);
$('#calendar').fullCalendar('removeEventSource', liteSource);
$('#calendar').fullCalendar('addEventSource', fullSource);
}
lastView = view.name;
}
},
timeFormat: { // for event elements
agendaDay: '',
agendaWeek: '',
month: '',
'': 'h(:mm)t' // default
},
});
//$('#calendar').limitEvents(2);
});
</script>
Tôi thậm chí đã sao chép mã của bạn chính xác như thế nào bạn làm điều đó bởi vì tôi nghĩ rằng có vấn đề với mã của tôi. ngay cả khi tôi thay đổi điều này:
//VIEW CHANGE - ALSO ADDS INITIAL SOURCES PER DAY VIEW
viewDisplay: function(view) {
$('#calendar').fullCalendar('removeEventSource', fullSource);
$('#calendar').fullCalendar('removeEventSource', liteSource);
$('#calendar').fullCalendar('addEventSource', fullSource); }
},
Nó vẫn tăng gấp đôi tải dữ liệu khi tôi chuyển từ chế độ xem được tải mặc định sang chế độ xem khác. Tôi bắt đầu nghĩ rằng đó chắc chắn là một lỗi trong FullCalendar. Lái xe cho tôi hạt
CHỈNH SỬA 2: MY GOD. Tôi không thể tin rằng nó cuối cùng cũng hoạt động!
Tôi không biết tại sao, nhưng tôi cần thiết để trao đổi xung quanh addEventSource
và removeEventSource
nó bây giờ trông giống như sau:
viewDisplay: function(view) {
if (lastView == undefined) { lastView = 'firstRun'; }
//alert("viewname: "+ view.name + "lastView: " + lastView);
if (view.name != lastView) {
if (view.name == 'agendaWeek') {
$('#calendar').fullCalendar('addEventSource', shortSource);
$('#calendar').fullCalendar('removeEventSource', longSource);
$('#calendar').fullCalendar('removeEventSource', shortSource);
}
if (view.name == 'agendaDay') {
//alert("in day: add litesource");
$('#calendar').fullCalendar('addEventSource', longSource);
$('#calendar').fullCalendar('removeEventSource', longSource);
$('#calendar').fullCalendar('removeEventSource', shortSource);
}
if (view.name == 'month') {
//alert("in month: Delete litesource");
$('#calendar').fullCalendar('addEventSource', shortSource);
$('#calendar').fullCalendar('removeEventSource', longSource);
$('#calendar').fullCalendar('removeEventSource', shortSource);
}
lastView = view.name;
}
},
ai cũng có thể trợ giúp việc này? – wired00
Holy crap, tôi đã cảm thấy nỗi đau của bạn trong vài tháng qua. Chỉ cần đi qua câu hỏi này sau khi vô số tìm kiếm. Hãy yên tâm, bài đăng của bạn đã giúp người khác! Cảm ơn. –
ahh tốt để xem :) – wired00