首页 > 解决方案 > 自定义按钮切换设置 filterResourcesWithEvents 忽略 jquery text() 调用

问题描述

我想添加一个自定义按钮来切换选项 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() 更新。

有没有人有什么建议?

标签: fullcalendarfullcalendar-scheduler

解决方案


经过一些实验后,我发现如果我使用类选择器来更改按钮,它就可以工作。我不确定为什么。

基本上,如果我将最后一行替换为:

$("button.fc-custom1-button").text(newFilterResourcesWithEvents ? 'Filter on' : 'Filter off');

我希望类命名保持一致。


推荐阅读