0
我綁定日期選擇器中的某些日期。但'date'在disableDates中始終未定義。有什麼我,我錯過了?我是新來的JavaScript,所以也許有一些我不明白呢。bootstrap Datepicker beforeShowDay:函數(日期)日期未定義
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);
}
}
};
};
當我嘗試它永遠不會進入功能。 – LadyBug
@LadyBug當你打開日期選擇器時,該函數會被調用 –
@LadyBug也沒有一個名爲'setEndDate'的方法你想用它做什麼 –