How to show and hide events in Fullcalendar v5

左心房为你撑大大i 提交于 2021-02-11 13:46:28

问题


I am trying to show and hide events according to extraparam value. However it does not work as expected. Any advice would be appreciated.

js:

document.addEventListener('DOMContentLoaded', function() {
var calendarEl = document.getElementById('calendar');
var calendar = new FullCalendar.Calendar(calendarEl, {
  now: '2020-07-11',
  scrollTime: '00:00',
  aspectRatio: 1.8,
  headerToolbar: {
    left: 'today prev,next',
    center: 'title',
    right: 'dayGridMonth,timeGridWeek,timeGridDay,listMonth'
  },
  initialView: 'dayGridMonth',
events: {
url: 'feed.php',
method: 'POST'
},
eventDidMount: function(arg) {  
var cs = document.querySelectorAll('input.cs:checked');
cs.forEach(function(v) {
    if(arg.event.extendedProps.cid == v.value) {
    arg.el.style.display = 'block';
    } else {
    arg.el.style.display = 'none';
  }
})
}  
});
calendar.render();

var csx = document.querySelectorAll(".cs")
csx.forEach(function(el) {
    el.addEventListener('change', function() {
        calendar.refetchEvents();
        console.log(el);
})
});
});

html:

<input class="cs" value="1" type="checkbox" checked>Calendar1<br>
<input class="cs" value="2" type="checkbox" checked>Calendar2
<div id='calendar'></div>

feed.php returns: [{"id":"1","title":"event1","start":"2020-07-07 19:30","end":"2020-07-08 19:30","backgroundColor":"#39CCCC","cid":"1"},{"id":"2","title":"event2","start":"2020-07-09 19:30","end":"2020-07-10 19:30","backgroundColor":"#F012BE","cid":"2"}]


回答1:


This worked:

eventDidMount: function(arg) {  
var cs = document.querySelectorAll('.cs');
cs.forEach(function(v) {
  if(v.checked){
    if(arg.event.extendedProps.cid === v.value) {
    arg.el.style.display = 'block';
    }
    } else {
    if(arg.event.extendedProps.cid === v.value) {
    arg.el.style.display = 'none';
    }
  }
})

}



来源:https://stackoverflow.com/questions/62863593/how-to-show-and-hide-events-in-fullcalendar-v5

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!