FullCalendar,4.2 - 如何在 eventClick 函数上更改事件 class
FullCalendar, 4.2 - How to change event class on eventClick function
我正在尝试在单击事件时更改事件的 CSS class,但我的运气为零。这是我的 JS:
var calendarEl = document.getElementById('calendar');
var calendar = new FullCalendar.Calendar(calendarEl, {
plugins: [ 'dayGrid', 'timeGrid', 'list' ],
header: {
left: 'prevYear,prev,next,nextYear',
center: 'title',
right: 'today dayGridMonth,timeGridWeek,timeGridDay,listWeek'
},
defaultView: 'dayGridMonth',
eventLimit: true,
views: {
month: {
eventLimit: 2
}
},
eventClick:function(info){
var id = info.event.extendedProps.timeslotid;
$.ajax({
url: 'index.php?option=com_cases&task=shifts.timeslotform&id='+id,
type: 'post',
dataType: 'html',
async: true,
success: function(response){
if (response) {
info.setProp( 'classNames', 'selected' ); // here's where the issue is
$('#sbcontent').empty();
$('#sbcontent').append(response);
}
}
});
},
events: 'index.php?option=com_cases&task=shifts.buildevents',
eventTimeFormat: { // like '14:30:00'
hour: 'numeric',
minute: '2-digit',
hour12: true
}
});
calendar.render();
我尝试了以下方法,但都导致了类似于以下的 JS 错误:"Uncaught TypeError: info.setProp is not a function"。
1) info.setProp( 'classNames', 'selected' );
2) info.el.setProp( 'classNames', 'selected' );
3) $(this).setProp( 'classNames', 'selected' );
4) $(this).addClass("selected");
我找到了一个类似的 post,但接受的答案没有添加或更改 class。相反,他们只是满足于更改事件的背景颜色。我不想那样做。我宁愿在活动中添加 CSS class。
类似Post:
感谢任何帮助!
info.event
是对 Event
的引用。所以你必须做info.event.setProp('yourProp', 'yourValue)
。请记住 classNames
属性是一个数组,而不是字符串。
我正在尝试在单击事件时更改事件的 CSS class,但我的运气为零。这是我的 JS:
var calendarEl = document.getElementById('calendar');
var calendar = new FullCalendar.Calendar(calendarEl, {
plugins: [ 'dayGrid', 'timeGrid', 'list' ],
header: {
left: 'prevYear,prev,next,nextYear',
center: 'title',
right: 'today dayGridMonth,timeGridWeek,timeGridDay,listWeek'
},
defaultView: 'dayGridMonth',
eventLimit: true,
views: {
month: {
eventLimit: 2
}
},
eventClick:function(info){
var id = info.event.extendedProps.timeslotid;
$.ajax({
url: 'index.php?option=com_cases&task=shifts.timeslotform&id='+id,
type: 'post',
dataType: 'html',
async: true,
success: function(response){
if (response) {
info.setProp( 'classNames', 'selected' ); // here's where the issue is
$('#sbcontent').empty();
$('#sbcontent').append(response);
}
}
});
},
events: 'index.php?option=com_cases&task=shifts.buildevents',
eventTimeFormat: { // like '14:30:00'
hour: 'numeric',
minute: '2-digit',
hour12: true
}
});
calendar.render();
我尝试了以下方法,但都导致了类似于以下的 JS 错误:"Uncaught TypeError: info.setProp is not a function"。
1) info.setProp( 'classNames', 'selected' );
2) info.el.setProp( 'classNames', 'selected' );
3) $(this).setProp( 'classNames', 'selected' );
4) $(this).addClass("selected");
我找到了一个类似的 post,但接受的答案没有添加或更改 class。相反,他们只是满足于更改事件的背景颜色。我不想那样做。我宁愿在活动中添加 CSS class。
类似Post:
感谢任何帮助!
info.event
是对 Event
的引用。所以你必须做info.event.setProp('yourProp', 'yourValue)
。请记住 classNames
属性是一个数组,而不是字符串。