0

私はjs関数内にjsコードを持っています...これにはif else条件が含まれています...同じ機能が含まれているのはパラメータの変更だけです...

したがって、唯一の違いは、関数に渡すパラメーター文字列です... if/else を使用して関数を呼び出します。残りのロジックは同じです.....

関数を呼び出すことは可能ですか?残りのロジックは同じです.....

return $(this).each(function () {
                if (coffeeId == "showCoffeeId") {
                    var todayDate = NoteWorklist.getDateTime("appleTime");
                    value.Year = todayDate.getFullYear();
                    value.Month = todayDate.getMonth() + 1;
                    value.Day = todayDate.getDate();
                    value.today = todayDate;
                    value.inputDate = todayDate;
                } else {
                    var todayDate = NoteWorklist.getDateTime("orangeTime");
                    value.Year = todayDate.getFullYear();
                    value.Month = todayDate.getMonth() + 1;
                    value.Day = todayDate.getDate();
                    value.today = todayDate;
                    value.inputDate = todayDate;
                }
            });
4

4 に答える 4

3

三項演算子を使用するだけです:

return $(this).each(function () {
       var todayDate = NoteWorklist.getDateTime(coffeeID == "showCoffeeId" ? "appleTime" : "orangeTime");
       value.Year = todayDate.getFullYear();
       value.Month = todayDate.getMonth() + 1;
       value.Day = todayDate.getDate();
       value.today = todayDate;
       value.inputDate = todayDate;
});
于 2013-09-19T15:06:29.087 に答える
0

このような?

return $(this).each(function () {
      var word =""
      if (coffeeId == "showCoffeeId") {
           word = "appleTime";
      } else {
           word = "orangeTime";
      }
     var todayDate = NoteWorklist.getDateTime(word);
     value.Year = todayDate.getFullYear();
     value.Month = todayDate.getMonth() + 1;
     value.Day = todayDate.getDate();
     value.today = todayDate;
     value.inputDate = todayDate;
});
于 2013-09-19T15:07:48.120 に答える
0

できますよ:

return $(this).each(function () {

    var todayDate = NoteWorklist.getDateTime(coffeeId == "showCoffeeId" ? "appleTime" : "orangeTime");
    value.Year = todayDate.getFullYear();
    value.Month = todayDate.getMonth() + 1;
    value.Day = todayDate.getDate();
    value.today = todayDate;
    value.inputDate = todayDate;

});
于 2013-09-19T15:06:18.250 に答える
0
    if (coffeeId == "showCoffeeId") {
       var todayDate = NoteWorklist.getDateTime("appleTime");
    } else {
      var todayDate = NoteWorklist.getDateTime("orangeTime");
    }

    value.Year = todayDate.getFullYear();
    value.Month = todayDate.getMonth() + 1;
    value.Day = todayDate.getDate();
    value.today = todayDate;
    value.inputDate = todayDate;
于 2013-09-19T15:06:29.290 に答える