-2

次のことを考慮してください。

function(){
  function getRate(source, scope) {
    var dateValue = $("Date", source).text() || "";
    if (!dateValue) {
      return null;
    }
    var d = new Date();
    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());

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

  return {
    getRates: function(xml){
      return getRates(xml);
    },
    getAllRates: function(source, scope){
      return new getRate();
    },
  };
}

この関数の外からdailyPriceを取得するにはどうすればよいですか

var getitall = getAllRates();

デバッガーで実行すると、関数に到達しますが、常に値が null として返されます。なぜ?

4

2 に答える 2

1
getAllRates: function(source, scope){
  return new getRate();
}

エラーはこのコードにあります。sourceandscopegetRate関数に渡す必要があります。これらのパラメーター$("Date", source).text()がないと、何も見つからないため、関数は を返します。これは、指定nullしたためです。

if (!dateValue) {
  return null;
}

これを修正するには、コードを次のように変更する必要があります。

getAllRates: function(source, scope){
  return getRate(source, scope);  // getRate needs to be passed the parameters
}
于 2013-08-07T14:12:29.420 に答える