我已经看到许多有关“ JavaScript仅在警报时起作用”的问题,但是答案仅针对那些问题。我正在使用Kendo Calender,并希望从数据库中的值突出显示特定日期。下面的代码仅在编写警报时才能正常工作。

 var duedates = [];
     function GetDueDates() {
                     $.ajax({
                     type: "POST",
                     url: "ChartBinder.asmx/GetDueDates",
                     data: '{}',
                     contentType: "application/json; charset=utf-8",
                     dataType: "json",
                     success: function (msg) {
                         duedates = $.parseJSON(msg.d);
                     },
                     error: function (msg) {
                         alert("error");
                     }
                 });
               }


  $(document).ready(function () {
               GetDueDates();


//当在此处插入警报时,功能起作用。

               var today = new Date();
               $("#calendar").kendoCalendar({
                   change: onChange,
                   navigate: onNavigate,
                   value: today,
                   dates: duedates,
                   month: {
                       // template for dates in month view
                       content: '# if ($.inArray(+data.date, data.dates) != -1) { #' +
                                    '<div class="' +
                                           "dataexist" +
                                             '"></div>' +
                                 '# } #' +
                                 '#= data.value #'
                   },
                   footer: "Today - #=kendo.toString(data, 'd') #"

               });

           $(document).find("#panelbar").kendoPanelBar({
               expandMode: "single"
           });
       });

最佳答案

得到了解决方案:更改了代码,如下所示:

var duedates = [];
    function GetDueDates() {
             $.ajax({
             type: "POST",
             url: "ChartBinder.asmx/GetDueDates",
             data: '{}',
             contentType: "application/json; charset=utf-8",
             dataType: "json",
             success: function (msg) {
                 duedates = $.parseJSON(msg.d);
                  },
             error: function (msg) {
                 alert("error");
             }    });
      }

     $(document).ready(function () {
         GetDueDates();
         setTimeout(function () { loadCalender(); }, 100);
         $(document).find("#panelbar").kendoPanelBar({
             expandMode: "single"
         });
         });


     function loadCalender() {
         var today = new Date();
         $("#calendar").kendoCalendar({
             change: onChange,
             navigate: onNavigate,
             value: today,
             dates: duedates,
             month: {
                 // template for dates in month view
                 content: '# if ($.inArray(+data.date, data.dates) != -1) { #' +
                                                 '<div class="' +
                                                        "dataexist" +
                                                          '"></div>' +
                                              '# } #' +
                                              '#= data.value #'
             },
             footer: "Today - #=kendo.toString(data, 'd') #"
             });
     }

关于c# - 剑道日历中要突出显示的日期仅在警报时起作用,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/14393855/

10-11 05:08