从SELECT列表中选择值时,现有的空数组var disableddates = [];
将填充一个"2016-03-21"格式的日期列表。
我想要一个jquery UI日期选择器来禁用事件后数组中的日期,但它根本不起作用。
$( "#datepicker" ).datepicker({
beforeShowDay: DisableSpecificDates,
dateFormat: "yy-mm-dd",
// rest of the code
function DisableSpecificDates(date) {
var string = jQuery.datepicker.formatDate('yy-mm-dd', date);
return [disableddates.indexOf(string) == -1];
}
当我在代码运行前将disableddates
设置为特定日期或多个日期时,它实际上会被禁用,所以这里唯一的问题是我无法让datepicker禁用上面提到的事件的日期。
此外,如果我使用事件beforeShow
而不是beforeShowDay
,则不会发生任何事情。
console.log
确认数组确实正在填充,所以我确信这只是日期选择器事件工作方式的问题。
有什么建议或解决方案吗?
终于找到了一个相当简单的解决方案。每次填充数组后,我都会在日期选择器上调用刷新方法。
$.each(data.response, function(i, item) {
disableddates.push(item);
});
// end array population
$( "#datepicker" ).datepicker( "refresh" );