0

ここに問題があります。日付の値が次のように表示されるカレンダーアプリがあります。

<div class="date-cell ng-binding" date-cell="" cell-data-index="getDateCellDataIndex(column, row)" ng-repeat="column in columns"> <div ng-click="onDateCellClick()" custom-date-cell="" ng-class="{today: cellData.isToday, 'current-month': cellData.isCurrentMonth}" class="ng-scope ng-binding current-month"> 1 </div> </div>

また、ajax を介してページに XML ドキュメントをロードし、日付値とその日付の価格を返します。dom 要素に表示される日付を xml から返されたデータに関連付けようとしています。その日付に価格値を追加します。

OK、私が持っている関数は惨めに失敗しています。実行して相関させるのではなく、すべての反復でdom要素からのすべての日付を返し、コンソールに記録するたびに、すべてのdom要素を実行します。

            function getRate(source, scope, dateSheet, dateSheetCtrl) {
                var dateValue = $("Date", source).text() || "";
                var thismonth = dateValue.substring(0,2);
                if (!dateValue) {
                    return null;
                }
                var d = new Date();
                var formattedmonthday = (getcalandardates < 10) ? '0' + getcalandardates : getcalandardates;
                var getcalandardates = $(".date-cell > div").text();
                var comparedates = getcalandardates.match(thisday);
                var thisday = dateValue.substring(3,5);
                var curr_date = d.getDate();
                var curr_month = d.getMonth() +1;
                var curr_mont = "0" + curr_month;
                var curr_year = d.getFullYear();
                var date_string = "0" + curr_month + "/0" + curr_date + "/" + curr_year;
                var dailyPrice = $("DailyPrice", source).text() || "";
                var weeklyPrice = $("WeeklyPrice", source).text() || "";
                var monthlyPrice = $("MonthlyPrice", source).text() || "";
                var isAvailable = $("IsAvailable", source).text() === "1";
                var minimumStay = Number($("MinimumStay", source).text());
                console.log(dailyPrice, weeklyPrice, monthlyPrice, isAvailable, minimumStay, dateValue , thismonth, getcalandardates);
                 if(curr_mont ==  thismonth  && comparedates == thisday) {
                    $(this, 'div').append('<p>' + dailyPrice + '</p>');
                    }

                if (curr_mont ==  thismonth  && getcalandardates == thisday){
                    $('.date-cell > div').append('<p>' + dailyPrice + '</p>');
                }
                /*if (date_string == dateValue) {
                    $('.date-cell > .today ').append('<p>' + dailyPrice + '</p>');
                }*/
                if (isNaN(minimumStay)) {
                    minimumStay = DEFAULT_MINIMUM_STAY;
                }

                return {
                    date: new Date(dateValue),
                    dailyPrice: dailyPrice,
                    weeklyPrice: weeklyPrice,
                    monthlyPrice: monthlyPrice,
                    reserved: !isAvailable,
                    minimumStay: minimumStay
                };

            }

今、これは私が使用している正確なif文です:

             if(curr_mont ==  thismonth  && comparedates == thisday) {
                $(this, 'div').append('<p>' + dailyPrice + '</p>');
                }

if ステートメントではなく for ステートメントを使用する必要があると感じていますが、それらを機能させることができないようです。次のことを試してみました。

                    $('.date-cell').each(function() {
                 $(this).find(".date-cell > div").text();
                 if(curr_mont ==  thismonth  && getcalandardates == thisday) {
                    $(this, 'div').append('<p>' + dailyPrice + '</p>');
                    }
                });

この:

                    $('.date-cell > div ').text().each(function() {
                 if(curr_mont ==  thismonth  && getcalandardates == thisday) {
                    $(this).append('<p>' + dailyPrice + '</p>');
                    }
                });

そして、これはこの 1 つの小さなステートメントの 4 時間目です...

xml は毎回コンソールに次のログを記録します。

90 495  true 2 10/01/2014 10  28  29  30  31  1  2  3  4  5  6  7  8  9  10  11  12  13  14  15  16  17  18  19  20  21  22  23  24  25  26  27  28  29  30  31  

クリス

/ * ****更新* ** * ** * /

これは私の新しい関数で、テキスト値を連続して取得しますが、dailyPrice の追加に失敗し、おそらく angularJS 内で実行されているために実行を停止しません:

                $(".date-cell > div").each(function () {
                    var gettextfunc = $(this).text();
                    if(curr_mont ==  thismonth  && gettextfunc == thisday) {
                    $(".date-cell > div").append('<p>' + dailyPrice + '</p>');
                    return false;
                    }
                    console.log(gettextfunc);
                });
4

0 に答える 0