Javascript jQuery UI日期选择器-类型错误:O未定义

Javascript jQuery UI日期选择器-类型错误:O未定义,javascript,jquery,ajax,cakephp,datepicker,Javascript,Jquery,Ajax,Cakephp,Datepicker,我正在制作CakePHP应用程序,目前我正在编写脚本来发出ajax请求,以突出显示jQuery datePicker的保留日期,并使用jQuery Accordion发出另一个ajax请求,以显示特定日期的保留信息 然而,我的日历并没有显示出来,我在Firebug控制台中得到了一个错误——“类型错误:O未定义。函数I(t,I){在jquery-ui.custom.min.js文件中”。脚本在实现几天的突出显示之前工作得很好 视图(calendar.ctp): 我明白了:我需要在beforeSho

我正在制作CakePHP应用程序,目前我正在编写脚本来发出ajax请求,以突出显示jQuery datePicker的保留日期,并使用jQuery Accordion发出另一个ajax请求,以显示特定日期的保留信息

然而,我的日历并没有显示出来,我在Firebug控制台中得到了一个错误——“类型错误:O未定义。函数I(t,I){在jquery-ui.custom.min.js文件中”。脚本在实现几天的突出显示之前工作得很好

视图(calendar.ctp):


我明白了:我需要在beforeShowDay函数中返回数组:

               beforeShowDay: function(date){                        
                    var y = date.getFullYear().toString(); // get full year
                    var m = (date.getMonth() + 1).toString(); // get month.
                    var d = date.getDate().toString(); // get Day
                    if(m.length == 1){ m = '0' + m; } // append zero(0) if single digit
                    if(d.length == 1){ d = '0' + d; } // append zero(0) if single digit                        
                    var currDate = y+'-'+m+'-'+d;
                    console.log(currDate);                        
                    //return [true, "ui-highlight", ''];                         

                    for(var i = 1; i < reservations.lenght; i++){
                        console.log(reservations[i].date);
                        if(reservations[i].date == currDate){
                            return [true, 'ui-highlight', ''];  
                        }/*else{
                            return [true];
                        }*/

                    }
                    return [true, '', ''];
                },
我的JSON数组是:
[Object{date=“2014-07-18”,count=“3”},Object{date=“2014-08-05”,count=“1”},Object{date=“2014-08-06”,count=“2”}]

可能是因为您拼写的“length”错了:

for(变量i=1;i
脚本的缩小版本用于生产,而不是开发。使用完整脚本可以获得更好的错误信息。
$(document).ready(function() {
    $.ajax({
        url: '<?php echo Router::url(array('controller' => 'streservations', 'action' => 'highlight'), true);?>',
        type: "GET",
        cache: false,           
        data: {
            action : 'showdates'
        },
        dataType: 'json',
        success: function(reservations){   
            //alert(reservations[0][0]);
            console.log(reservations);
            $( "#datepicker" ).datepicker({ //initialize datepicker
                defaultDate: '<?php echo $this->Time->format('Y-m-d', time()) ?>',
                maxDate: '<?php echo $this->Time->format('Y-m-d', '+1 month') ?>',
                dateFormat: 'yy-mm-dd',
                beforeShowDay: function(date){                        
                    var y = date.getFullYear().toString(); // get full year
                    var m = (date.getMonth() + 1).toString(); // get month.
                    var d = date.getDate().toString(); // get Day
                    if(m.length == 1){ m = '0' + m; } // append zero(0) if single digit
                    if(d.length == 1){ d = '0' + d; } // append zero(0) if single digit                        
                    var currDate = y+'-'+m+'-'+d;
                    console.log(currDate);
                    /*
                    $.each(reservations, function(k, v){
                        //alert(v.date + ' ' + v.count);
                        if(v.date == currDate && v.count > 3){
                            return [true, "ui-highlight"];
                        }
                        else{
                            return [true];
                        }
                    });
                    /*for(var i = 0; i < reservations.lenght; i++){
                        alert(reservations[i][1]);
                        if(*reservations[i][1] == currDate*reservations.indexOf(currDate) >= 0){
                            return [true, "ui-highlight"];  
                        }else{
                            return [true];
                        }
                    }*/                     
                },
                onSelect : function(dateText,inst) //when selecting date, make AJAX call to show accordion
                {
                    $.ajax({
                        url: '<?php echo Router::url(array('controller' => 'streservations', 'action' => 'hours'), true);?>',
                        type: "GET",
                        cache: false,
                        dataType: 'json',
                        data: {
                            action: 'accord',
                            date: dateText
                        },
                        success: function(data){
                            $("#hours").accordion({collapsible: true, clearStyle: true, heightStyle: "content"});
                            $('#hours').empty();
                            $.each(data, function(k, v){
                                $('#hours').append('<li><h3><div>' + v.title + ' ' + v.start + '</div></h3><div>' + 'Operation: ' + v.name + '</br>' + 'Name: ' + v.title + '</br>'+ 'Time: ' + v.start + '</br>'+'</div></li>');
                            });
                            $("#hours").accordion( "refresh" );
                        }
                    });
                }
            });
        } 
    });
});
unselectable = (otherMonth && !selectOtherMonths) || !daySettings[0] ||
               beforeShowDay: function(date){                        
                    var y = date.getFullYear().toString(); // get full year
                    var m = (date.getMonth() + 1).toString(); // get month.
                    var d = date.getDate().toString(); // get Day
                    if(m.length == 1){ m = '0' + m; } // append zero(0) if single digit
                    if(d.length == 1){ d = '0' + d; } // append zero(0) if single digit                        
                    var currDate = y+'-'+m+'-'+d;
                    console.log(currDate);                        
                    //return [true, "ui-highlight", ''];                         

                    for(var i = 1; i < reservations.lenght; i++){
                        console.log(reservations[i].date);
                        if(reservations[i].date == currDate){
                            return [true, 'ui-highlight', ''];  
                        }/*else{
                            return [true];
                        }*/

                    }
                    return [true, '', ''];
                },
if(reservations[i].date == currDate){
                            return [true, 'ui-highlight', ''];  
                        }
 for(var i = 1; i < reservations.lenght; i++){