0

在继续 淘汰 js 与 datetimepicker 绑定给出了一个异常 我现在可以使用带有淘汰的 datetimepicker 但我无法使用同一工具的时间选择器选项我尝试过的代码嵌入到以下 jsfiddle 但正在抛出一个错误

<code>
http://jsfiddle.net/saqibshakil/scdET/
</code>

编辑后检查控制台

4

1 回答 1

3

看起来调用getDate不会timepicker返回实际的Date.

看来您可以datetimepicker成功调用它。因此,您的绑定将如下所示:

ko.bindingHandlers.timepicker = {
    init: function (element, valueAccessor, allBindingsAccessor) {
        //initialize timepicker with some optional options
        var options = allBindingsAccessor().timepickerOptions || {};
        $(element).timepicker(options);

        //handle the field changing
        ko.utils.registerEventHandler(element, "change", function () {
            var observable = valueAccessor();
            observable($(element).datetimepicker("getDate"));
        });

        //handle disposal (if KO removes by the template binding)
        ko.utils.domNodeDisposal.addDisposeCallback(element, function () {
            $(element).timepicker("destroy");
        });

    },
    //update the control when the view model changes
    update: function (element, valueAccessor) {

        var value = ko.utils.unwrapObservable(valueAccessor()),
            current = $(element).datetimepicker("getDate");

        if (value - current !== 0) {
            $(element).datetimepicker("setDate", value);
        }
    }
};

更新示例:http: //jsfiddle.net/rniemeyer/L3BNw/

于 2013-07-23T14:27:11.177 回答