[英]How to reload data in jQuery-UI Datepicker?
Here is situation: 这是情况:
I have JQuery-UI datepicker with passed data from a jquery ajax request. 我有JQuery-UI datepicker与来自jquery ajax请求的传递数据。
$(document).ready(function() {
$.ajax({
url: "load-calendar",
dataType: "json",
success: function(calendarEvents){
$("#calendar_1").datepicker({
beforeShowDay: function(date) {
var m = date.getMonth(), d = date.getDate(), y = date.getFullYear();
for (i = 0; i < calendarEvents.length; i++) {
if($.inArray(y + '-' + (m+1) + '-' + d,calendarEvents) != -1) {
return [true, 'ui-state-busy', false];
}
}
return [true];
}
});
}
});
});
It works fine, and I can see calendar with highlighted busy days. 它工作正常,我可以看到带有突出显示的繁忙日程的日历。
Now I would like to autorefresh this calendar (every minute), so that user could automatically see new highlighted days. 现在,我想(每分钟)自动刷新此日历,以便用户可以自动看到新的突出显示的日期。 Is this possible? 这可能吗?
I have tried using setInterval function, but with no success. 我尝试使用setInterval函数,但没有成功。
So any experiences/ideas are welcome. 因此,欢迎任何经验/想法。 Thanks in advance. 提前致谢。
If your ajax response is fast enough, you could make that call in the beforeShow event of the datepicker: 如果您的ajax响应足够快,则可以在datepicker的beforeShow事件中进行该调用:
$('#calendar_1').datepicker({
beforeShow: function(input, inst) { //code to update calandar events here// }
});
If using datepicker inline: 如果使用内联日期选择器:
function refreshDatePicker(){
//your ajax call here
}
$(function(){
// Document is ready
setInterval ( "refreshDatePicker()", 1000 );
});
I have solved this problem: 我已经解决了这个问题:
<div id="show_calendars"></div>
$(document).ready(function() {
var update = function(){
$('#show_calendars')
.load('/reload-calendars')
.fadeIn("slow");
};
var auto_refresh = setInterval(function(){update();}, 10000);
update();
});
Function reload-calendars : 功能重载日历 :
<div id="calendar_1"></div>
$(document).ready(function() {
var busyDays = [<? echo $data;?>];
var date = new Date();
$( "#calendar_1").datepicker({
dateFormat: 'yy-mm-dd',
beforeShowDay: function(date) {
var m = date.getMonth(), d = date.getDate(), y = date.getFullYear();
for (i = 0; i < busyDays.length; i++) {
if($.inArray(y + '-' + (m+1) + '-' + d,busyDays) != -1) {
return [true, 'ui-state-busy', false];
}
}
return [true];
}
});
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.