1

我想显示一个日期选择器以仅显示年份和月份,并将当前月份作为默认视图。问题是它仍然显示日视图,我看不出有什么问题,有什么建议吗?

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>
4

2 回答 2

0

尝试使用dateFormat 而不是像这样format你的小提琴中使用:

$(document).ready(function() {
    $('#input_date').datepicker({
        dateFormat: 'mm/yy',
        viewMode: "months", 
        minViewMode: "years",
        startView: "month"
    });
});

在这里工作:http: //jsfiddle.net/jham/ESX6Z/1/

于 2014-02-14T10:58:26.013 回答
0

根据this,您需要设置startView属性:

$(element).datepicker({
    startView: year
})
于 2013-02-25T16:04:54.910 回答