为什么在我的日历组件中使用state作为字符串不起作用



我正试图在日历上标记一个日期,这很有效:

<Calendar 
  markedDates={{
  '2020-07-22': {selected: true, marked: false, selectedColor: '#ff7f00'},}}
   onDayPress={(day) => this.manageGroups(day)}
/>

然而,当我试图将日期从硬编码的日期更改为状态时,它不起作用。以下是我的做法。

<Calendar 
      markedDates={{
      '${this.state.currentDate}%': {selected: true, marked: false, selectedColor: '#ff7f00'},}}
       onDayPress={(day) => this.manageGroups(day)}
    />

这是有原因的吗?

这样试试,

<Calendar 
  markedDates={{
  `${this.state.currentDate}`: {selected: true, marked: false, selectedColor: '#ff7f00'},}}
   onDayPress={(day) => this.manageGroups(day)}
/>

最新更新