简体   繁体   English

如何从日期范围选择器获取值

[英]How to get values from date range picker

I'm using the Date Range Picker for Bootstrap to select a range of dates, and everything looks good, my only problem is that after I have picked the dates and submit the form, I don't know how to get the values (dates) I have picked. 我正在使用BootstrapDate Range Picker选择日期范围 ,并且一切看起来都很好,我唯一的问题是,在选择日期并提交表单后,我不知道如何获取值(日期)我选择了。

Below you can see my daterangepicker settings: 您可以在下面看到我的daterangepicker设置:

<input ui-jq="daterangepicker" ui-options="{
      format: 'DD-MM-YYYY',
      startDate: '{{ first }}',
      endDate: '{{ second }}',
      separator: ' til ',
      showWeekNumbers: true,
      locale: {
           applyLabel: 'Vælg datoer',
           cancelLabel: 'Annuller',
           fromLabel: 'Fra',
           toLabel: 'Til',
           firstDay: 1
      }
}" ng-model="plane.date" class="form-control" placeholder="Dato" />

As you can see I have tried to add ng-model , but still without luck. 如您所见,我尝试添加ng-model ,但仍然没有运气。

You have 2 options: 您有2个选择:

Set it on apply event: (don't forget the $scope.$apply part) 在apply事件上设置它:(不要忘记$ scope。$ apply部分)

 angular.element('input#dataRange') = datePicker;
 datePicker.on('apply.daterangepicker', function (ev, picker) {
                $scope.$apply(function () {
                    $scope.fromDate = picker.startDate.format("YYYY-MM-DD");
                    $scope.toDate = picker.endDate.format("YYYY-MM-DD");
                });
            });

or get the values at any time: 或随时获取值:

angular.element('input#dataRange')= datePicker;
$scope.fromDate = datePicker.data('daterangepicker').startDate.format("YYYY-MM-DD");
$scope.toDate = datePicker.data('daterangepicker').endDate.format("YYYY-MM-DD");

This is also useful if you want to get the date on loss of focus (blur) if the user edits the input manually: 如果您要获得用户手动编辑输入时失去焦点(模糊)的日期,这也很有用:

datePicker.on('blur', function (ev) {
                    $scope.$apply(function () {
                        $scope.fromDate = datePicker.data('daterangepicker').startDate.format("YYYY-MM-DD");
                        $scope.toDate = datePicker.data('daterangepicker').endDate.format("YYYY-MM-DD");
                    });
                });

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM