我想添加一个自定义按钮来切换选项filterResourcesWithEvents。理想情况下,按钮会将样式更改为按下状态,但现在我只是尝试在设置选项后更改按钮文本。问题是文本没有改变。
人们可以在CodePen中找到一个完整的示例。
custom1: {
text: 'Filter off',
click: function() {
var cal = $('#calendar').fullCalendar('getCalendar');
var newFilterResourcesWithEvents = ! cal.option('filterResourcesWithEvents');
cal.option('filterResourcesWithEvents', newFilterResourcesWithEvents);
// The following line being ignored.
$(this).text(newFilterResourcesWithEvents ? 'Filter on' : 'Filter off');
}},
我怀疑调度程序选项函数可能与 text(( 更新有关
。有人有什么建议吗?
经过一番实验,我发现如果我使用类选择器来更改按钮,它就可以工作。我不太确定为什么。
基本上,如果我将最后一行替换为:
$("button.fc-custom1-button").text(newFilterResourcesWithEvents ? 'Filter on' : 'Filter off');
我希望类命名保持一致。