UI Calendar Control with Date Populated

I'm having issues with binding the calendar control based on jquery-UI. I'm using Knockout and REST API to get the date value and it gets populated correctly in the input text box as below, but the calendar does not reflect the correct binding with the date populated? What needs to be done to reflect the correct date in the calendar.

<div class="form-group">
    <label for="LaunchDate">Launch Date</label>
<div class="input-group"                 
 <input type="text" data-bind="value: Launch_Date"  class="date-picker form-control input-sm" id="LaunchDate"/>
<label for="LaunchDate" class="input-group-addon btn"><span class="glyphicon glyphicon-calendar"></span> </label>
</div>
</div>

Knockout JS Code:
self.Launch_Date = ko.observable(moment.utc(data.d.Launch_Date).format("YYYY-MMM-DD"));

DatePicker Code JQuery UI and Bootstrap:
$(".date-picker").datepicker();


Use the dateFormat option. The format the picker is set to use should match the format of the date you're initializing it with.

$(".date-picker").datepicker({ dateFormat: "yy-mm-dd" });

EDIT: Fiddle


我假设你从data.d.Launch_Date得到了值。有些时候REST api和json用反斜杠返回日期值,你需要解析它,var dt = new Date(parseInt(data.d.LaunchDate)然后你可以尝试这种格式'MM / DD / YYYY'而不是使用MMM。

链接地址: http://www.djcxy.com/p/83816.html

上一篇: 与'与'绑定?

下一篇: 带日期填充的UI日历控件