我想使用诸如引导导航导航选项卡之类的菜单来显示和隐藏事件。
在选项卡上时,我单击 Event1 仅显示带有“cid:“1””的事件,Event2 仅显示带有“cid:“2””的事件,并且 ALL 显示所有事件。
谁能帮我开发这个?基于这个问题Fullcalendar v5 how to show and hide events with checkbox我制作了一个基于复选框的代码笔,仅用于启动... https://codepen.io/berettatim/pen/rNeXwLm
html:
<div class="row">
<div class="col-md-12">
<ul class="nav nav-tabs">
<li onclick="javascript:CalendarTypeSet(1)" class="nav-item"><a class="nav-link active" data-toggle="tab" href="#CalTab1" style="font-size:16px;"><b>EVENT1</b></a></li>
<li onclick="javascript:CalendarTypeSet(2)" class="nav-item"><a class="nav-link" data-toggle="tab" href="#CalTab2" style="font-size:16px;"><b>EVENT2</b></a></li>
<li onclick="javascript:CalendarTypeSet(3)" class="nav-item"><a class="nav-link" data-toggle="tab" href="#CalTab3" style="font-size:16px;"><b>EVENT3</b></a></li>
<li onclick="javascript:CalendarTypeSet('all')" class="nav-item"><a class="nav-link" data-toggle="tab" href="#CalTabAll" style="font-size:16px;"><b>ALL</b></a></li>
</ul>
</div>
<div class="col-md-12">
<input class="cs" value="1" type="checkbox" checked>Calendar1<br>
<input class="cs" value="2" type="checkbox" checked>Calendar2
<div id='calendar'></div>
</div>
脚本:
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: function (fetchInfo, successCallback, failureCallback) {
successCallback([
{
id: "1",
title: "event1",
start: "2020-07-01 19:30",
end: "2020-07-02 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"
}
]);
},
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";
}
}
});
}
});
calendar.render();
var csx = document.querySelectorAll(".cs");
csx.forEach(function (el) {
el.addEventListener("change", function () {
calendar.refetchEvents();
console.log(el);
});
});
});
//Not sure for this...
function CalendarTypeSet(fTip)
{
var x = document.getElementById('cal_tip');
x.value=fTip;
//$('#calendar').fullCalendar('rerenderEvents');
calendar.rerenderEvents('#calendar');
}