fullcalendar - 自定义按钮切换设置 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() 更新。
有没有人有什么建议?
解决方案
经过一些实验后,我发现如果我使用类选择器来更改按钮,它就可以工作。我不确定为什么。
基本上,如果我将最后一行替换为:
$("button.fc-custom1-button").text(newFilterResourcesWithEvents ? 'Filter on' : 'Filter off');
我希望类命名保持一致。
推荐阅读
- sql-server - DATA 文件夹所需的权限
- javascript - 如何使用 Angular 6 在后台执行相同的操作以执行相同的操作?
- javascript - 如何使用反应钩子更新对象?
- javascript - EventSource 停止从服务器接收任何更新
- python - 如何在 python flask 和 jinja2 中设置环境变量
- docker - 无法在运行命令中挂载 -v
- flutter - 如何在 Flutter 的 Dialogs 中访问 Provider 提供者
- python - 调用 pa.hdfs.connect 时出现 NoSuchMethodError
- angularjs - angularjs 错误:[$injector:strictdi] 函数($httpProvider)未使用显式注释,无法在严格模式下调用
- c - 如何使用 CRTSCTS 监听串口