微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

javascript-react-datepicker,默认情况下显示months

我们在日历实现中使用react-datepicker.显示认月份由monthsShowd datepicker控制
组件属性.当我们说2时,它表示下个月的本月.

我正在使用如下的reat DatePicker

<DatePicker 
  customInput={<CustomInput disableDateSelection={this.props.dateProps.disableDateSelection} />}
  className="w-dtsr-date-picker"
  selected={this.state.startDate}  //called when the date is clicked 
  onChange={this.handleChange}    //called only when the value is chnaged 
  monthsShown={2}     //number of months to be shown 
  minDate={this.props.dateProps.minDate}  //min days to be shown in the calendar 
  maxDate={this.props.dateProps.maxDate}  //max days to be shown in the calendar 
  onChangeRaw={this.handleDateChangeRaw}  //preventing the user from manually entering the dates or text in the input text Box 
  dayClassName={date => date.getTime() === new Date(this.props.dateProps.defaultDate).getTime() && this.props.dateProps.disableDefaultDate ? 'random' : undefined}
  //dayClassName - to disable the proposed forecast dates or actual dates if user has already selected/proposed the same forecast/actual dates
  disabled={this.props.dateProps.disableDateSelection}
/>

有没有办法显示上个月和本月?
例如,如果当前月份是4月,我们想显示3月和4月而不是4月-5月.

最佳答案
不幸的是,在react-datepicker存储库中查看该组件的源代码,似乎它将始终显示当月和此后的几个月,这由monthShown属性控制.除了派生github存储库并自己添加功能(或提交功能请求)以外,别无其他办法让它做您想要的事情.有问题的问题:

calendar.jsx

var monthList = [];
for (var i = 0; i < this.props.monthsShown; ++i) {
  var monthsToAdd = i - this.props.monthSelectedIn;
  var monthDate = addMonths(this.state.date,monthsToAdd);
  var monthKey = `month-${i}`;

monthsShown属性控制显示的月份,认值为1.为了使它能够执行您想要的操作,可以添加一个标志来反转月份的增加,而改为减去.

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐