sap.m.DatePicker setDateValue仅在日历nopt输入字段中设置

时间:2016-08-18 07:00:49

标签: datepicker sapui5 sap.m

我正在使用sap.m.DatePicker。通过按钮我将当前日期增加一天。

.divKolon {width:50px;height:50px;padding:10px;border:3px solid #00000; background-color: #E98A7E;float:left;}

.divUstKolon {width:50px;height:50px;padding:10px;border:3px solid #DD4B39;  text-align:center;float:left;margin-right:20px;}
.divIcKolon{width:50px;height : 20px !important;padding:10px;border:3px solid #00000;background-color: #FFFFFF ; text-align:center;float:left;margin-left:5px;}
.shadow(@shadow){
  -webkit-box-shadow:@shadow;
  -mox-box-shadow:@shadow;
  box-shadow:@shadow;
}

.divIcKolonGrup{border 3px solid #00000;}    

.label-danger{      
    margin-left:10px;
    margin-top:10px;        
}

但是日期仅在选择器的日历部分增加而不是在输入字段中。enter image description here

我做错了什么还是有些错误?

2 个答案:

答案 0 :(得分:0)

如果控件的数据中的更改未反映在UI中,则可以重新呈现控件。

更新DatePicker控件的值后,使用rerender,如下所示。

datepicker.rerender();

答案 1 :(得分:0)

您必须操纵控件中新的日期实例,而不是旧的实例。

const newDate = new Date(datePicker.getDateValue().getTime()); // create a new copy
newDate.setDate(datePicker.getDateValue().getDate() +1); // manipulate the new date instead
datePicker.setDateValue(newDate);

发件人:https://jsbin.com/hulopec/edit?js,output

由于JS日期是对象,并且由于JS中的对象与其他引用持有人共享 ,所以操纵原始日期值也会对控件的内部值产生副作用。

通常,使用const代替var可以避免此类意外副作用。