如何设置与 KnockoutJS 绑定的 jQuery DatePicker 的默认值?

发布于 2024-11-19 22:47:31 字数 908 浏览 2 评论 0原文

使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

凉墨 2024-11-26 22:47:31

该问题最终与如何返回 myDateObject 供日期选择器访问有关。当真正需要访问原始数据时,正在访问的自定义 ko.dependentObservable 会以自定义格式返回日期。

为了解决该问题,创建了另一个 ko.dependentObservable 来允许直接访问原始日期。

The issue ended up being related to how myDateObject was being returned back for the datepicker to access. The custom ko.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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文