我想显示一个日期选择器以仅显示年份和月份,并将当前月份作为默认视图。问题是它仍然显示日视图,我看不出有什么问题,有什么建议吗?
ko.bindingHandlers.datePickerMonthYear =
init: (element, valueAccessor, allBindingsAccessor, viewModel) ->
value = valueAccessor()
$('#dpMonths').data({date: value()});
$('#dpMonths').datepicker('update');
$(element).datepicker(
viewMode: "years",
minViewMode: "months"
).on('changeDate', (ev) ->
$(this).datepicker('hide')
).on('click', (ev) ->
$(this).datepicker('show')
)
ko.bindingHandlers.validationCore.init(element, valueAccessor,allBindingsAccessor)
,
update: (element, valueAccessor, allBindingsAccessor, viewModel) ->
HTML
<div id="dpMonths" class="input-append date" data-date-minviewmode="months" data-date-viewmode="years" data-date-format="mm/yyyy" data-bind="datePickerMonthYear: startDate">
<input class="span2" type="text" readonly="" data-bind="value: startDate">
<span class="add-on">
<i class="icon-calendar"></i>
</span>
</div>