1

我使用 jquery Datepicker ui。( http://jqueryui.com/datepicker/ )

当我从 ajax 回来时,我想为这些日子着色,日期为着色。

我有这个:

     $(document).ready(function()
    {
        getAllDays();
        $("#datepicker").datepicker({
            changeMonth: true,
            changeYear: true,
            onChangeMonthYear: getAllDays,
            beforeShowDay: highlightDays,
            dateFormat: 'DD, d MM, yy',
            altField: '#date_due',
            altFormat: 'yy-mm-dd',
            firstDay: 1
        });
    });

作为日期选择器。现在的问题是我在 getAllDays 函数中为我的日子着色,我在 highlightDays 函数中为日子着色。但是 highlightdays 在 getAllDays 之前运行,因此该月的颜色不正确(像上个月一样着色)

如果需要,这些是 2 个功能:

      function getAllDays(year, month) {


        $.ajax({
            async: false,
            cache: false,
            url: "AantalUrenAjax?_d" + (new Date().getTime()) + "&jaar=" + year + "&maand=" + month,
            dataType: "json",
            success: function(data) {
                // loop over dayUsage array result
                $.each(data, function(index, value) {
                    // add to different arrays depending on how much time is allocated in estimates

                    enabledDays.push(value);

                });



            }
        });

    }

      function highlightDays(date) {

        for (var i = 0; i < enabledDays.length; i++) {

            // console.log((enabledDays[i].jaar,enabledDays[i].maand,enabledDays[i].dag).toString());

            if (new Date(enabledDays[i].Jaar, enabledDays[i].Maand, enabledDays[i].Dag).toString() === date.toString()) {
                textdisplay = "Er zijn nog " + enabledDays[i].aantalafspraken.toString() + " Vrije afspraken";
                switch (true) {
                    case (enabledDays[i].aantalafspraken < 1):
                        return [true, "Volzet", textdisplay];
                        break;
                    case (enabledDays[i].aantalafspraken < 3):
                        return [true, "BijnaVolzet", textdisplay];
                        break;
                    default:
                        return [true, 'Vrij', textdisplay];
                }

            }

        }

        return [true, ''];






    }

我现在尝试修复这个问题 20 小时,但我无法修复它:(

4

1 回答 1

0

您是否尝试将您的高光时刻移动到您的 getAllDays 函数的成功回调中?

success: function(data) {
    // loop over dayUsage array result
    $.each(data, function(index, value) {
        // add to different arrays depending on how much time is allocated in estimates

        enabledDays.push(value);

    });

    highlightDays...

}
于 2013-09-30T14:58:50.277 回答