0

我正在为我的项目使用react-native-calendars。我可以选择 days ON/OFF

但是,我希望用户在选择日期时有限制。所以我想让用户接受3 days

如果超过3days are selected,禁用selected method.

知道我该怎么做吗?任何意见或建议都会非常有帮助。

提前致谢!

这是我的代码:

 onDaySelect = (day) => {

    const _selectedDay = moment(day.dateString).format(_format);
    let selected = true;
    let markedDates = {}
    if (this.state._markedDates[_selectedDay]) {
      selected = !this.state._markedDates[_selectedDay].selected;
      markedDates = this.state._markedDates[_selectedDay];
    }

    markedDates = {...markedDates, ...{ selected }};
    const updatedMarkedDates = {...this.state._markedDates, ...{ [_selectedDay]: markedDates } }
    this.setState({ _markedDates: updatedMarkedDates },
    ()=> {console.log(this.state._markedDates, 'this.state._markedDates')});
    this.setState({bday:day.dateString}
    , ()=> {
    store.requestObject.date = this.state.bday
    })
  }


 <Calendar
                   onDayPress={this.onDaySelect}
                   markedDates={this.state._markedDates}
                   markingType={'multi-dot'}
                   monthFormat={'yyyy MMMM'}/>

状态:

const _format = 'YYYY-MM-DD'
const _today = moment().format(_format)
  initialState = {
       [_today]: {disabled: true}
   }

this.state = {_markedDates: this.initialState}
4

0 回答 0