首先我没有流利的英语所以我很抱歉:s
所以我的第一个问题是我在函数“get_events”的else上有一个无限循环,我真的不明白为什么
第二个是当我点击一个复选框时,我必须更新事件(如果复选框是真的,我点击它,一些事件必须被删除,如果它是假的,一些事件必须出现) 但我可以清除所有事件
jest
<script>
var cards = <?=$cards_json?>;
var events = [];
var calendarEl;
var calendar;
$(function() {
getCalendar();
var count = $(".check:checked").length;
console.log(cards);
$(".check").prop('checked', true);
get_events();
$('.check').click(function(){
var checklist = [];
const checkboxes = document.querySelectorAll(".check:checked");
// console.log(checkboxes);
checklist.length = 0;
for (const checkbox of checkboxes) {
if(checkbox.checked){
checklist.push(checkbox.value);
console.log("pourquoi :" + checkbox.value);
}
}
getNewCards(checklist);
});
});
function get_events(){
events.length = 0;
var tmp = [];
tmp.length = 0;
calendar.removeAllEvents();
console.log(cards + " boucle infinie");
for (let card of cards){
if(card){
if(card.dueDate > '<?=date("Y-m-d")?>'){
console.log("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa");
tmp.push( {
title : card.title,
start : card.dueDate,
color: "green",
});
}else{
console.log("infinite loop");
tmp.push( {
title : card.title,
start : card.dueDate,
color: '#' + card.BoardID + card.BoardID + card.BoardID,
textColor: 'red',
});
}
}
}
events = tmp;
for(let event of events){
calendar.addEvent(event);
}
}
function getCalendar() {
calendarEl = document.getElementById('calendar');
calendar = new FullCalendar.Calendar(calendarEl, {
headerToolbar: {
left: 'prev,next today',
center: 'title',
right: 'dayGridMonth,timeGridWeek,listMonth'
},
initialDate: '<?=date("Y-m-d")?>',
navLinks: true,
businessHours: true,
selectable: true,
events: events,
});
calendar.render();
}
function getNewCards(checklist){
$.post('calendar/test',{boards:checklist},function(data){
cards = data;
console.log("testtttt" + cards);
}).done(function() {
get_events();
});
}
</script>
感谢您的帮助,我真的很抱歉我的英语!
答案 0 :(得分:0)
这一行:calendar.removeAllEvents();
-- 我认为这不是一个真正的函数,您是否遇到错误?我想你想要calendar.removeEvents();
https://fullcalendar.io/docs/v3/removeEvents
无限循环问题可能源于 get_events()
函数被调用了 3 次。 calendar
初始化中的第一个,然后在您选中复选框后立即,然后在 $(function() {
init 函数中再次立即,然后在 getNewCards
你应该
getNewCards()
将调用 get_events()
删除对 get_events()
的所有其他调用