无法使用淘汰赛触发 beforeShowDay

unable to trigger beforeShowDay using knockout

我是 knockoutJS 的新手,我正在尝试使用自定义绑定来绑定日期选择器。下面是我的视图模型 JS 文件。

/*Date picker value binder for knockout*/
ko.bindingHandlers.datepicker = {
init: function (element, valueAccessor, allBindingsAccessor) {

    var options = {
        showOtherMonths: true,
        selectOtherMonths: true,
       beforeShowDay: function (date) {

            alert('looking for an alert');
            return [false, '', 'available'];
        },
        showOn: "both"
    };

    $(element).datepicker(options);

    $(element).datepicker(options).on("changeDate", function (ev) {
        var observable = valueAccessor();
        observable(ev.date);

    });
},
update: function (element, valueAccessor) {
    var value = ko.utils.unwrapObservable(valueAccessor());
    $(element).datepicker("setValue", value);
}
};



/*View model*/
 function ViewModel() {
   var self = this;
   self.dateFromClient = ko.observable('12/12/2010')
                        .extend({ required: true });
 }


$(document).ready(function () {

//model binding with validation
var vm = new ViewModel();

ko.applyBindings(vm);

});

下面是我的看法。

 <div>

        <input type="text" readonly="readonly" data-date-format="dd-mm-yyyy" class="datepicker" data-bind="datepicker: dateFromClient" />

  </div>

我正在寻找的是禁止在日历上点击几个日期。这就是我开始返回 false 的原因(希望选择器上的每个日期都被禁用。)但我没有看到任何日期被禁用。

有人可以指导我这样做的正确途径吗?

尝试这样的事情

查看:

<input type="text" readonly="readonly" data-bind="datepicker:$data.dateFromClient" />

viewModel:

ko.bindingHandlers.datepicker = {
    init: function (element, valueAccessor, allBindingsAccessor) {
        var options = {
            showOtherMonths: true,
            selectOtherMonths: true,
            beforeShowDay: function (date) {
                alert('looking for an alert');
                return [false, '', 'available'];
            },
            showOn: "both"
        };

        $(element).datepicker(options);

        $(element).datepicker(options).on("changeDate", function (ev) {
            var observable = valueAccessor();
            observable(ev.date);

        });
    },
    update: function (element, valueAccessor) {
        var value = ko.utils.unwrapObservable(valueAccessor());
        current = $(element).datepicker("getDate");
        if (value - current !== 0) {
            $(element).datepicker("setDate", value);   
        }
    }
};


/*View model*/
var ViewModel = function () {
    var self = this;
    self.dateFromClient = ko.observable();
}

ko.applyBindings(new ViewModel());

工作fiddlehere