如何设置与 KnockoutJS 绑定的 jQuery DatePicker 的默认值?
使用 KnockoutJS 进行 jQuery 日期选择器此处,我有以下设置:
<span data-bind="text: myDateObject"></span>
<input style="display:none"
data-bind="enable: enabledBoolean,
datepicker: myDateObject,
datepickerOptions: {
buttonImage: '/Content/calendar.png',
buttonImageOnly: true,
showOn: 'button',
showOtherMonths: true,
selectOtherMonths: true,
defaultDate: new Date(),
minDate: '-1m',
maxDate: '+1m' }" />
myDateObject
是一个 javascript Date 对象,可以设置为 null。但是,当我单击日历图像并弹出日期选择器时,它始终默认为最大日期,即使我已经调出日期选择器并设置了一次值。
正如您在上面的代码示例中看到的,我试图将 defaultDate 设置为当前日期,但它似乎完全忽略了这一点。也许这是由于 KnockoutJS 绑定造成的?
Using KnockoutJS for a jQuery datepicker found here, I have the following setup:
<span data-bind="text: myDateObject"></span>
<input style="display:none"
data-bind="enable: enabledBoolean,
datepicker: myDateObject,
datepickerOptions: {
buttonImage: '/Content/calendar.png',
buttonImageOnly: true,
showOn: 'button',
showOtherMonths: true,
selectOtherMonths: true,
defaultDate: new Date(),
minDate: '-1m',
maxDate: '+1m' }" />
myDateObject
is a javascript Date object that could be set to null. When I click on the calendar image and the datepicker pops up, though, it always defaults to the maximum date, even if I have already brought up the datepicker and set a value once already.
As you can see in the code sample above, I'm trying to set the defaultDate to the current date, but it seems to ignore this completely. Perhaps this is due to the KnockoutJS bindings?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
该问题最终与如何返回 myDateObject 供日期选择器访问有关。当真正需要访问原始数据时,正在访问的自定义 ko.dependentObservable 会以自定义格式返回日期。
为了解决该问题,创建了另一个 ko.dependentObservable 来允许直接访问原始日期。
The issue ended up being related to how
myDateObject
was being returned back for the datepicker to access. The customko.dependentObservable
being accessed was returning the date in a custom format, when it really needed access to the raw data.To resolve the issue, another
ko.dependentObservable
was created to allow direct access to the raw Date.