Using Knockout.js how do bind a Date property to a HTML5 date picker?

后端 未结 8 576
南旧
南旧 2021-01-04 00:37

(this only works in Chrome at the moment as most browsers don\'t yet implement date picker for input type=\"date\")

In the following example MyDate starts o

8条回答
  •  再見小時候
    2021-01-04 01:29

    These days is so much easier with Moment.js

    this.sessionDate = ko.observable(moment().format('YYYY-MM-DD'));
    this.getFormattedDate = () => { return moment(this.sessionDate()'YYYY-MM-DD').format('MM/DD/YYYY') }; // Note this is ES2015 syntax
    

    In your html you can bind it with

    
    

    And display it formatted as

    Loading Date

    No need to create custom bindings, and you can use a shim for older browsers.

提交回复
热议问题