jQuery UI datepicker change event not caught by KnockoutJS

后端 未结 13 2407
长发绾君心
长发绾君心 2020-11-22 16:16

I\'m trying to use KnockoutJS with jQuery UI. I have an input element with a datepicker attached. I\'m currently running knockout.debug.1.2.1.js and it seems th

13条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-11-22 16:40

    Based on Ryan's solution, myDate returns the standard date string, which is not the ideal one in my case. I used date.js to parse the value so it will always return the date format you want. Take a look at this example fiddle Example.

    update: function(element, valueAccessor) {
        var value = ko.utils.unwrapObservable(valueAccessor()),
            current = $(element).datepicker("getDate");
        var d = Date.parse(value);
        if (value - current !== 0) {
            $(element).datepicker("setDate", d.toString("MM/dd/yyyy"));   
        }
    }
    

提交回复
热议问题