2

我正在尝试禁用 jquery ui 的 datepicker 函数的某些日子,但是此代码返回错误:daySettings is undefinedhttp://code.jquery.com/ui/1.9.2/jquery-ui.js中。这似乎是正确的,我不知道......请帮助!

         var $j = jQuery.noConflict(); 
     $j(document).ready(function() {
        var group_id = <? echo $bp->groups->current_group->id; ?>;
        var userid = <? echo $bp->loggedin_user->id; ?>;
        var myBadDates = new Array ();
    function checkAvailability(mydate){
    jQuery.post(  
        ajaxurl,
        {   
        action : 'check_date',
        verificadata: "true", userid: userid, group_id: group_id
        },
        function( response ) {
        obj = JSON.parse(response);
        var key, quanti = 0; 
            for(key in obj.prenotati) { 
                if(obj.prenotati.hasOwnProperty(key)) { 
                    var datafrom = obj.prenotati[quanti].datafrom;
                    var datato = obj.prenotati[quanti].datato;
                    myBadDates.push(datafrom);
                    myBadDates.push(datato);
                    quanti++;
                }
            }
            var ritorno = true;
            var returnclass ="available";
            checkdate = $j.datepicker.formatDate('yy-mm-dd', mydate);
                for(var i = 0; i < myBadDates.length; i++) { 
                    $j(myBadDates[i])
                        if(myBadDates[i] == checkdate) { 
                        ritorno = false; returnclass="unavailable"; 
                        } 
                }
                return [ritorno,returnclass]; 
        }
    )
}       

/* $myBadDates = new array("2013-03-03","2013-03-05");      
function checkAvailability(mydate){
        var $return=true;
        var $returnclass ="available";
        $checkdate = $j.datepicker.formatDate('yy-mm-dd', mydate);
        for(var i = 0; i < $myBadDates.length; i++) { 
            if($myBadDates[i] == $checkdate) { 
                $return = false; $returnclass= "unavailable"; 
            } 
        } 
        return [$return,$returnclass]; 
        } */
            $j('#datafrom').datepicker({
             dateFormat : 'yy-mm-dd',
             beforeShowDay: checkAvailability,
             onSelect: function(dateText, inst) {
                $j("#datafrom").val(dateText);
            }
        });
        $j('#datato').datepicker({
             dateFormat : 'yy-mm-dd',
             beforeShowDay: checkAvailability,
                onSelect: function(dateText, inst) {
                    $j("#datato").val(dateText);
                }
        }); 
 });
4

1 回答 1

0

您的问题在于范围,您正在尝试在成功方法中获得return结果,但这实际上并不是您的函数返回的内容post

我在下面所做的只是将返回变量的声明移到函数作用域的顶部,然后我return还在函数作用域的顶部添加了语句

var $j = jQuery.noConflict(); 
     $j(document).ready(function() {
        var group_id = <? echo $bp->groups->current_group->id; ?>;
        var userid = <? echo $bp->loggedin_user->id; ?>;
        var $myBadDates = new Array ();
    jQuery.post(  
        ajaxurl,
        {   
        action : 'check_date',
        verificadata: "true", userid: userid, group_id: group_id
        },
        function( response ) {
        obj = JSON.parse(response);
        var key, count = 0; 
            for(key in obj.prenotati) { 
                if(obj.prenotati.hasOwnProperty(key)) { 
                    var datafrom = obj.prenotati[count].datafrom;
                    var datato = obj.prenotati[count].datato;
                    $myBadDates.push(datafrom); 
                    $myBadDates.push(datato);
                    count++;
                }
            }
            $j($myBadDates).appendTo("#item-meta");
        }
    )     
        function checkAvailability(mydate){
        var $return=true;
        var $returnclass ="available";
            checkdate = $j.datepicker.formatDate('yy-mm-dd', mydate);
                for(var i = 0; i < $myBadDates.length; i++) { 
                        if($myBadDates[i] == checkdate) { 
                    //  alert($myBadDates[i]);
                        $return = false; $returnclass= "unavailable"; 
                        } 
                }
        return [$return,$returnclass];  
        }  
于 2013-03-12T15:34:11.513 回答