1

kendo-time-picker在我的 Angular js 项目中使用。下拉菜单默认为空白。但是,当我打开下拉菜单时,它应该第一次显示上午 8:00 。我怎样才能做到这一点。

下面是我的代码片段。

<input class="form-control kendotimepicker" name="StartTimeVal" kendo-time-picker
   ng-model="startTimeValModel"
   ng-change="startTimeChange(startTimeValModel)"
   ng-required=true
   ng-pattern="/^(0?[1-9]|1[012])(:[0-5]\d) [AP][M]$/"
   interval="5"
   title="hh:mm AM/PM">
4

2 回答 2

2

您可以使用该scrollTop()功能,如下所示:

<!DOCTYPE html>
    <html>
    <head>
        <meta charset="utf-8"/>
        <title>Kendo UI Snippet</title>

        <link rel="stylesheet" href="https://kendo.cdn.telerik.com/2019.1.220/styles/kendo.common.min.css"/>
        <link rel="stylesheet" href="https://kendo.cdn.telerik.com/2019.1.220/styles/kendo.rtl.min.css"/>
        <link rel="stylesheet" href="https://kendo.cdn.telerik.com/2019.1.220/styles/kendo.silver.min.css"/>
        <link rel="stylesheet" href="https://kendo.cdn.telerik.com/2019.1.220/styles/kendo.mobile.all.min.css"/>

        <script src="https://code.jquery.com/jquery-1.12.4.min.js"></script>
        <script src="https://kendo.cdn.telerik.com/2019.1.220/js/kendo.all.min.js"></script>
    </head>
    <body>
      
    <input id="timepicker" />
    <script>
    $("#timepicker").kendoTimePicker({
        open: function(e) {
            if (!e.sender.value()) { // Run only if no value was selected
                setTimeout(() => {
                    let containerElement = e.sender.timeView.list;
                    let listElement = containerElement.children().first();
                    containerElement.scrollTop(listElement.height() * 8 / 24)
                }, 0);
            }
        }
    });
    </script>
    </body>
    </html>

于 2019-04-07T11:38:59.847 回答
1

您可以使用 k-value 属性并设置默认值

演示

angular.module("KendoDemos", [ "kendo.directives" ])
      .controller("MyCtrl", function($scope){
          $scope.getType = function(x) {
              return typeof x;
          };
    			
          $scope.isDate = function(x) {
              return x instanceof Date;
          };
    
    			$scope.value = '08:00 AM';
      })
<!DOCTYPE html>
<html>
<head>
    <base href="http://demos.telerik.com/kendo-ui/datetimepicker/angular">
    <style>html { font-size: 14px; font-family: Arial, Helvetica, sans-serif; }</style>
    <title></title>
    <link rel="stylesheet" href="//kendo.cdn.telerik.com/2016.3.1118/styles/kendo.common.min.css" />
    <link rel="stylesheet" href="//kendo.cdn.telerik.com/2016.3.1118/styles/kendo.default.min.css" />
    <link rel="stylesheet" href="//kendo.cdn.telerik.com/2016.3.1118/styles/kendo.default.mobile.min.css" />

    <script src="//kendo.cdn.telerik.com/2016.3.1118/js/jquery.min.js"></script>
    <script src="//kendo.cdn.telerik.com/2016.3.1118/js/angular.min.js"></script>
    <script src="//kendo.cdn.telerik.com/2016.3.1118/js/kendo.all.min.js"></script>
</head>
<body>
<div id="example" ng-app="KendoDemos">
    <div class="demo-section k-content" ng-controller="MyCtrl">
        <h4>Select time:</h4>
        <input kendo-time-picker="dtp"
               k-value="'08:00 AM'"
               ng-model="value"
               style="width: 100%;" />
{{value}}
</div>
</div>

于 2019-04-06T17:50:27.227 回答