MultipleDatePicker - 如何在下拉列表中显示特定的年份范围?

时间:2018-04-04 05:42:37

标签: javascript angularjs multiple-date-picker

我已经开始学习Multipledatepicker,我正在进行自定义。我有一个场景,我将日历带到任何年/月选择的最后日期。现在它运作良好但现在我需要在 1960-2028 的下拉列表中显示多年。

但是官方文档说“当你选择一年时,它会重新选择选择,以便始终拥有所选年份的相同范围'。我不希望这在选定年份选择年份。

<multiple-date-picker change-year-past="5" change-year-future="10"/>

我该怎么做?

的js

 getYearsForSelect = function () {
                    var now = moment(),
                        changeYearPast = Math.max(0, parseInt(scope.changeYearPast, 10) || 0),
                        changeYearFuture = Math.max(0, parseInt(scope.changeYearFuture, 10) || 0),
                        min = moment(scope.month).subtract(changeYearPast, 'year'),
                        max = moment(scope.month).add(changeYearFuture, 'year'),
                        result = [];
                    max.add(1, 'year');
                    for (var m = moment(min); max.isAfter(m, 'YEAR'); m.add(1, 'year')) {
                        if ((!scope.disallowBackPastMonths || (m.isAfter(now, 'year') || m.isSame(now, 'year'))) && (!scope.disallowGoFuturMonths || (m.isBefore(now, 'year') || m.isSame(now, 'year')))) {
                            result.push(m.format('YYYY'));
                        }
                    }
                    return result;
                };

1 个答案:

答案 0 :(得分:0)

我想出了这个:)

     getYearsForSelect = function () {
                    // var now = moment(),
                    //     changeYearPast = Math.max(0, parseInt(scope.changeYearPast, 10) || 0),
                    //     changeYearFuture = Math.max(0, parseInt(scope.changeYearFuture, 10) || 0),
                    //     min = moment(scope.month).subtract(changeYearPast, 'year'),
                    //     max = moment(scope.month).add(changeYearFuture, 'year'),
                      var  result = [];
                        // max.add(1, 'year');
                        for (var m = 1960; m<=2028 ; m++) {
                            // if ((!scope.disallowBackPastMonths || (m.isAfter(now, 'year') || m.isSame(now, 'year'))) && (!scope.disallowGoFuturMonths || (m.isBefore(now, 'year') || m.isSame(now, 'year')))) {
                                result.push(m);
                            // }
                        }
                    return result;
                }