AngularUI Datepickerを接続しましたが、カレンダーで別の日付を選択すると、ngModel属性を介してそれに接続されているISO日付の時間部分がリセットされることを除いて、十分に機能します。時間を保つように設定するにはどうすればよいですか?
1 に答える
0
ディレクティブで肉付けすることで問題を解決しました。
input(ng-model="event.date_started", j-datepicker)
div(ng-model="event.date_started", j-datepicker)
.directive 'jDatepicker', ->
require: 'ngModel'
link: (scope, elem, attrs, ngModel) ->
# check if elem is an input so when the input
# gains focus it doesn't spawn another calender
if not elem.is('input')
elem.datepicker
onSelect: (dateText) ->
# get the original ISO date and new date
oldDate = new Date ngModel.$modelValue
newDate = new Date dateText
# set the new month and day onto the original ISO date
oldDate.setUTCMonth newDate.getUTCMonth()
oldDate.setUTCDate newDate.getUTCDate()
scope.$apply () ->
# update the model with the new info
ngModel.$setViewValue oldDate.toISOString()
ngModel.$render = () ->
date = new Date ngModel.$viewValue
# set the default highlighted date on the calender
elem.datepicker 'setDate', date
# this renders the date value on the
# input element in the format I want
elem.val date.toDateString()
于 2012-11-03T04:38:57.313 に答える