我想在日期选择器中删除一些日期。但是,'date'在disableDates中始终未定义。有什么我想念的吗?我是javascript的新手,所以也许有些东西我还不太了解。
ko.bindingHandlers.datepicker = {
init: function(element, valueAccessor, allBindingsAccessor) {
var options = allBindingsAccessor().datepickerOptions || {},
$el = $(element);
//initialize datepicker with some optional options
$el.datepicker(options);
$el.datepicker('setEndDate', new Date);
$el.datepicker('beforeShowDay', disableDates());
function disableDates(date) {
self.getDates();
var showDate = true;
for (var i = 0; i < self.dates.length; i++) {
if (date.toDateString() === new Date(self.dates()[i].ReportingDate).toDateString()) {
showDate = false;
}
}
return [showDate, ""];
}
//handle the field changing
ko.utils.registerEventHandler(element, "change", function() {
var observable = valueAccessor();
observable($el.datepicker("getDate"));
});
//handle disposal (if KO removes by the template binding)
ko.utils.domNodeDisposal.addDisposeCallback(element, function() {
$el.datepicker("destroy");
});
},
update: function (element) {
var value = self.ReportingDate(),
$el = $(element),
current = $el.datepicker("getDate");
if (value - current !== 0) {
$el.datepicker("setDate", value);
}
}
};
};
答案 0 :(得分:0)
尝试
//initialize datepicker with some optional options
$.extend(options, {
beforeShowDay: disableDates
})
$el.datepicker(options);
$el.datepicker('setEndDate', new Date);