在 html 中我有这个选择
:
<input class="form-control input-sm" data-bind="datepicker: StartDate" />
它不在循环内部。只是一个独立的。在 knockout 模型中,我尝试将其定义如下:
function VacationRequestsViewModel() {
var self = this;
self.StartDate = new Date();
....
}
这也是......
$(document).on('ready',
function () {
masterVM = new VacationRequestsViewModel();
ko.applyBindings(masterVM);
});
在页面加载时,我明白了
Uncaught TypeError: Unable to process binding "datepicker: function (){return StartDate }" Message: observable is not a function
我已经成功声明了很多其他事情。可观察到的。 ObservableArray 的 Bool 。不确定我在这里做错了什么。
最佳答案
根据错误消息,我猜测日期选择器绑定(bind)期望 StartDate 是可观察的。尝试将其声明为 self.StartDate = ko.observable(new Date());
关于javascript - 声明日期选择器时 knockout "observable is not a function",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44184386/