[英]how to disable dates using data stored in database using react and api
新的反应,所以我不确定我是否走在正确的道路上。 我将日期存储在数据库中,我想检索这些日期并在日期选择器中禁用这些日期。 这是我填充数据的内容,我做了一个componentDidMount,然后我想我会为每个循环做一个来显示每个单独的日期,更改日期格式,然后是一些如何禁用日期的方法。 任何反馈都会有所帮助。
class Reservation extends Component{
constructor(props) {
super(props)
this.state = {
blocked: [],
startDate: null,
endDate: null,
focusedInput: null,
}
}
continue = e => {
e.preventDefault();
this.props.onClick();
}
componentDidMount(){
pocService.getBlocked().then((response) => {
const blockedDates = response.data
// blockedDates = new Date(unavaliableDates)
this.setState({ blocked: blockedDates})
});
}
render(){
const customDates = this.state.blocked.map((block, i) => {
return <tr key = {block.blockedDateId + i }><td> { block.reservedDate} </td>
</tr>
});
console.log("this is a list" + customDates);
const disableCustomDt = current => {
return !customDates.includes(current.format('mm-dd-YYYY'));
}
const { checkIn, checkOut, blocked, handleChange } = this.props;
return(
<>
<div>
<label>
<Calendar
onChange={handleChange('checkIn')}
value={disableCustomDt }
tileClassName="content"
/>
<input
type="date"
name="checkIn"
value={checkIn}
placeholder="dd-mm-yyyy"
maxDate={disableCustomDt }
onChange={handleChange('checkIn')}
/>
<DatePicker
timeFormat={false}
isValidDate={disableCustomDt}
/>
</label>
</div>
}
}
export default Reservation;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.