0

我正在尝试使用微风和淘汰赛绑定到日期。从 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" 知道为什么日期是“无效的”吗?

4

2 回答 2

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'

于 2013-08-30T00:51:50.220 回答
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"

现在你会得到你需要的......你也可以保存更新的日期

于 2013-08-30T00:46:17.087 回答