【问题标题】:Bs datepicker's value updates but display value does not updatebs datepicker的值更新但显示值不更新
【发布时间】:2021-01-21 16:41:01
【问题描述】:

angularjs的版本是1.5.11。

我在我的 .NET MVC 项目中使用来自 angularjs 的 bs-datepicker 元素。这是我的日期选择器和在我的应用中用作按钮的几张图片:

<input class="form-control"
                       type="text"
                       placeholder="Pick a Date (default today)."
                       data-date-format="MM-dd-yyyy"
                       data-min-date="today"
                       bs-datepicker
                       data-autoclose="true"
                       ng-model="tos.appointmentDay"
                       ng-change="tos.updateAppointments()"
                       style="width: 100px;" />
<div class="appointment-buttons">
                        <i class="fa fa-arrow-left fa-lg"
                             ng-click="tos.decrementAppointmentDate()" />
                        <i class="fa fa-arrow-right fa-lg"
                             ng-click="tos.incrementAppointmentDate()" />
                    </div>

我有两个箭头图像元素用作按钮,在我的约会应用程序中向前或向后更改一天。这些按钮确实与此日期选择器一起正确更改了日期(通过在我的控制器中使用我的函数),我可以看到它反映在我的代码中用于显示日期的日期选择器弹出窗口和其他文本输出中。

但是,当我通过两个箭头按钮更新应用程序中的约会日期属性的值时,我的所有输出都会更新,包括日期选择器的实际值,但日期选择器的文本输入字段中的显示值会更新不更新。为什么弹窗中的日期选择器值会正确更新,但 bs-datepicker 的文本输入字段没有更新?

【问题讨论】:

    标签: angularjs typescript razor datepicker


    【解决方案1】:

    解决方案是,当您在 JavaScript/TypeScript 中对绑定到元素的日期对象(在本例中为日期选择器)执行 setDate 调用时,它不会更新数据选择器。这是因为您需要显式分配已绑定到元素的对象以更改其值。这对于 bs-datepicker 元素是正确的,对于 angularjs 也是如此。

    你应该:

    //Do this.
    var temp = original;
    temp.setDate(newDate);
    original = temp;
    
    //Don't do this by itself.
    original.setDate(newDate);
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-11-27
      • 1970-01-01
      • 2016-04-18
      • 2015-10-31
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-07-25
      相关资源
      最近更新 更多