我正在尝试使用微风和淘汰赛绑定日期。从BreezeController返回的数据是预期的。但我在调试器中看到了这一点:
TripDate: function dependentObservable() {
__ko_proto__: function (evaluatorFunctionOrOptions, evaluatorFunctionTarget, options) {
_latestValue: Wed Dec 31 1969 19:00:00 GMT-0500 (Eastern Standard Time)
__proto__: Invalid Date
从数据库服务器返回的json数据是:
TripDate: "2013-07-21T00:00:00.000"
知道为什么日期是“无效”?
答案 0 :(得分:0)
在视图模型中使用它
ko.bindingHandlers.datepicker = {
init: function(element, valueAccessor, allBindingsAccessor) {
//initialize datepicker with some optional options
var options = allBindingsAccessor().datepickerOptions || {};
$(element).datepicker(options);
//handle the field changing
ko.utils.registerEventHandler(element, "change", function () {
var observable = valueAccessor();
observable($(element).datepicker("getDate"));
});
//handle disposal (if KO removes by the template binding)
ko.utils.domNodeDisposal.addDisposeCallback(element, function() {
$(element).datepicker("destroy");
});
},
//update the control when the view model changes
update: function(element, valueAccessor) {
var value = ko.utils.unwrapObservable(valueAccessor());
$(element).datepicker("setDate", value);
}
};
然后在html中
data-bind="datepicker:tripDate"
现在你将得到你需要的东西......你也可以保存更新的日期
答案 1 :(得分:0)
检查是否只想显示
ko.bindingHandlers.dateString = {
update: function(element, valueAccessor, allBindingsAccessor, viewModel) {
var value = valueAccessor(),
allBindings = allBindingsAccessor();
var valueUnwrapped = ko.utils.unwrapObservable(value);
var pattern = allBindings.datePattern || 'MM/dd/yyyy';
$(element).text(valueUnwrapped.toString(pattern));
}
}
在html中将'datepicker'替换为'dateString'