2

私が書いた(ほとんど変更された)2つの関数があり、それらを1つの関数に組み合わせる必要があります。最初の関数は、ユーザーが部門を選択したときに呼び出され、コールバックを実行して日を検索し、それらを配列に追加します。2番目の関数は、jQuerydatepickerの日をブロックします。私は適切に機能するためにブロックされた日を取得しました、私はちょうど2つの機能を組み合わせる方法を理解することができません。私はさまざまな方法を試しましたが、何も機能していないようです。

// load calendar buttons
$(document).ready(function(){
$("#Return_Date").datepicker( { beforeShowDay: nonWorkingDates, showOn: "both",    numberOfMonths: 2, minDate: 0, maxDate: "364D", gotoCurrent: true, buttonImageOnly: true }   );
$("#Depart_Date").datepicker( { beforeShowDay: nonWorkingDates, showOn: "both", numberOfMonths: 2, minDate: 0, maxDate: "364D", gotoCurrent: true, buttonImageOnly: true    }   );
});

// load blocked days - this loads properly into the date pickers above
function nonWorkingDates(date){
// create an array for closedDates
var closedDates = [[3,22,2012], [3,25,2012], [4,15,2012], [4,24,2012], [4,25,2012]];

//loop through the list of closed Dates
for (i = 0; i < closedDates.length; i++) {      
    // if the date is found set it as disabled. January is 0, February 1, etc so a -1 is needed on the month value
    if (date.getMonth() == closedDates[i][0] - 1 && date.getDate() == closedDates[i][1] &&  date.getFullYear() == closedDates[i][2]) {
        return [false];
    }
}
return [true];
};

//load in closed dates i need the BlockedTravelDays array to pull into the date pickers. the array here loads fine
$(document).ready(function NoTravelDays() {
$("#TripApprovalDepartment").change(function() {
    var value = $.trim($("#TripApprovalDepartment").val());
    if (value.length > 0) {
        $.getJSON("../approval.cfc?method=getBlockedDays&returnFormat=json", {DeptID:value}, function(res,code) {
            // create an Array
            var BlockedTravelDays = [];
            for (var i = 0; i < res.DATA.length; i++) { 
                // store the travel days in the array
                BlockedTravelDays.push(res.DATA[i][2]);
            }; // end for loop
        }); // end JSON
    } // end if
});
});
4

1 に答える 1

2

簡単な解決策は、さらに3番目の関数から両方の関数を呼び出すことです。これには、一部の人が必要とする可能性のある柔軟性はありませんが、同じ柔軟性は必要ないようです。したがって、次のようなものが得られます。

$(document).ready(function()
{
    function1();
    function2();
}

すでに無名関数を使用していることを確認すると、その関数は代わりに他の関数を呼び出すことができ、次のようになります。

$(document).ready(function(){
    $("#Return_Date").datepicker( { beforeShowDay: nonWorkingDates, showOn: "both",    numberOfMonths: 2, minDate: 0, maxDate: "364D", gotoCurrent: true, buttonImageOnly: true }   );
    $("#Depart_Date").datepicker( { beforeShowDay: nonWorkingDates, showOn: "both", numberOfMonths: 2, minDate: 0, maxDate: "364D", gotoCurrent: true, buttonImageOnly: true    }   );

    NoTravelDays();
});
于 2012-04-20T20:08:07.393 に答える