jQuery 如何刷新日期选择器?函数 .datePickerMultiMonth()
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2129480/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
how to refresh datepicker? function .datePickerMultiMonth()
提问by Markus
Really like datepicker. Thanks a lot for this great library!
真的很喜欢日期选择器。非常感谢这个伟大的图书馆!
I have got one question for you based in this example (inline datepicker):
基于这个例子(内联日期选择器),我有一个问题要问你:
http://www.kelvinluck.com/assets/jquery/datePicker/v2/demo/datePickerMultiMonth5.html
http://www.kelvinluck.com/assets/jquery/datePicker/v2/demo/datePickerMultiMonth5.html
I added a "renderCallback" function to disable week days based on checkboxes... (e.g. when saturday-checkbox is checked disable all saturdays shown).
我添加了一个“renderCallback”函数来禁用基于复选框的工作日......(例如,当周六复选框被选中时禁用显示的所有周六)。
This works perfectly fine when initializing the calender with datePickerMultiMonth().
这在使用 datePickerMultiMonth() 初始化日历时非常有效。
But how can I refresh the inline calender when one of the checkboxes is changed (e.g. deselect monday-checkbox)?
但是,当其中一个复选框发生更改(例如取消选择 monday-checkbox)时,如何刷新内联日历?
As-is: when I select / deselect a checkbox the datepicker remains unchanged.. only after manually changing to the next month it updates and disables e.g. all mondays... this should immediately happen when changing the monday-checkbox.
原样:当我选择/取消选择一个复选框时,日期选择器保持不变..只有在手动更改到下个月后,它才会更新并禁用例如所有星期一......这应该在更改星期一复选框时立即发生。
Do you have any idea how I can refresh the datepicket? Thanks a lot for your help!
你知道我如何刷新 datepicket 吗?非常感谢你的帮助!
Cheers, Markus
干杯,马库斯
回答by BlondinkaBrain
.datepicker( "refresh" )
You can find it on http://jqueryui.com/demos/datepicker/#method-refreshclick the "Methods" tab
您可以在http://jqueryui.com/demos/datepicker/#method-refresh上找到它, 单击“方法”选项卡
回答by vitch
Probably the easiest way to solve the problem is to remove the existing calendar and then rerender it. e.g.:
解决问题的最简单方法可能是删除现有日历,然后重新渲染它。例如:
$mm.empty().datePickerMultiMonth({});
However, this has some drawbacks as the state of your date picker isn't maintained (e.g. displayed month, selected dates etc).
但是,这有一些缺点,因为您的日期选择器的状态没有得到维护(例如显示的月份、选定的日期等)。
So I just made some changes to the plugin and introduced a new method: dpmmRerenderCalendar
on the multimonth picker (and the corresponding dpRerenderCalendar
on the date picker itself).
所以我只是对插件进行了一些更改并引入了一种新方法:dpmmRerenderCalendar
在多月选择器上(以及dpRerenderCalendar
日期选择器本身上的相应方法)。
You can see an example of it in action here:
你可以在这里看到它的一个例子:
http://www.kelvinluck.com/assets/jquery/datePicker/v2/demo/datePickerMultiMonth7.html
http://www.kelvinluck.com/assets/jquery/datePicker/v2/demo/datePickerMultiMonth7.html
And can grab the latest plugin code from my site or the googlecode repository.
并且可以从我的站点或 googlecode 存储库中获取最新的插件代码。
回答by Tobias Cohen
After having a bit of a look at the source, it seems you'll have to do something like this:
稍微查看一下源代码后,您似乎必须执行以下操作:
$.event._dpCache[$('.date-pick')[0]._dpId]._applyRenderCallbacks()
or possibly this:
或者可能是这样的:
$.event._dpCache[$('.date-pick')[0]._dpId]._rerenderCalendar()
The $.event._dpCache[$('.date-pick')[0]._dpId]
part is used to get the first internal DatePicker object matching the css '.date-pick'
, which is needed to access the internal _applyRenderCallbacks
and _rerenderCalendar
functions.
该$.event._dpCache[$('.date-pick')[0]._dpId]
部分用于获取与 css 匹配的第一个内部 DatePicker 对象'.date-pick'
,这是访问内部_applyRenderCallbacks
和_rerenderCalendar
函数所需的。
Unfortunately, this does access the internal structure of the plugin, so it is possible it might break when new versions are released, however I couldn't find any publicly accessible way to refresh the calendar.
不幸的是,这确实访问了插件的内部结构,因此在发布新版本时它可能会中断,但是我找不到任何可公开访问的方法来刷新日历。