简体   繁体   English

jQuery datepicker onChangeMonthYear在当前月份不触发

[英]jQuery datepicker onChangeMonthYear doesn't fire on current month

I'm using the datepicker inline, highlighting the dates that has events. 我正在使用datepicker内联,突出显示具有事件的日期。 Every time the month changes, it has to load the new events from the server. 每月每次更改时,都必须从服务器加载新事件。 The problem is, the onChangeMonthYear only fires on months different from the current month. 问题是,onChangeMonthYear仅在与当前月份不同的月份触发。 For instance, if the is august, it fires on all previous months (july, june, may...) and all following months (september, october...), but not when I change back to august. 例如,如果八月,它将在之前的所有月份(七月,六月,五月...)和随后的所有月份(九月,十月...)触发,但是当我改回八月时不会触发。 This is my code: 这是我的代码:

function highlightDates(date) {
    for ( var i = 0; i < agenda.length; i++) {
        var start = agenda[i].start.toShortDate();
        var end = agenda[i].end.toShortDate();

        if (start >= date && end <= date) {
            return [ true, 'dateHasEvent' ];
        }
    }

    return [ true, '' ];
}

Date.prototype.toShortDate = function() {
    var date = new Date(this.getFullYear(), this.getMonth(), this.getDate());
    return date;
};

function monthChanged(year, month, instance) {
    var date = new Date(year, month - 1);

    $.getJSON('json.do', {
        time : date.getTime()
    }, updateCalendars);
}

function updateCalendars(data, status) {
    agenda = data;
    $('#calendar').datepicker('refresh');
}

var agenda = [];

$(function() {    
    $('#calendar').datepicker( {
        beforeShowDay : highlightDates,
        onChangeMonthYear : monthChanged,
        changeMonth : false,
        changeYear : false,
        showButtonPanel : false
    });
});

Does anybody know if this is a bug or expected behaviour? 有人知道这是错误还是预期的行为?

Well, that was stupid on my part. 好吧,那对我来说是愚蠢的。 The problem was the getJSON method. 问题是getJSON方法。 It is apparently very picky about what json it accepts. 显然,它接受什么json非常挑剔。 So after I produced correct json, everything worked as it should. 因此,在生成正确的json之后,一切都会按预期进行。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM