AngularJS下使用Kendo的DatePicker控制項日期有時不顯示

來源:互聯網
上載者:User

標籤:style   blog   ar   color   使用   sp   java   for   on   

在AngularJS下使用Kendo的DatePicker控制項時,在k-ng-model綁定了日期對象,但是頁面在顯示時,有時控制項顯示空白,但是有時又正常,具有一定隨機性,在stackoverflow中也沒找到類似狀況和解決方案,經過分析跟蹤後,確認問題是DatePicker控制項的問題,控制項說明文檔中所述ng-model和k-ng-model是有區別的:

  • The first is to demonstrate the difference between ng-model="dateString" and k-ng-model="dateObject"dateString is bound to the input field‘s contents as a string — so it gets the formatted string date, while dateObject is bound to the widget‘s value() which in the case of DatePicker returns a JS Date object. As you can see, we can apply the Angular date filter on it.

ng-model綁定的是一個string類型的變數,k-ng-model則綁定一個物件變數,在兩者都綁定的情形下,控制項顯示的是ng-model綁定的變數,所以可以把控制項的ng-model和k-ng-model都賦值,這樣就能保證值正常又顯示正確。

HTML代碼:

<input kendo-date-picker k-ng-model="datestart" ng-model="datestartString" />

JavaScript代碼:

$scope.datestart = new Date();$scope.datestartString = $scope.datestart.getFullYear() + ‘-‘ + ($scope.datestart.getMonth() + 1) + ‘-‘ + $scope.datestart.getDate();

有一點要注意,js日期對象的getMonth返回的月份為0到11,所以上面代碼中才加了1。

AngularJS下使用Kendo的DatePicker控制項日期有時不顯示

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.