我react-native-calendars
在我的项目中使用。我正在尝试选择多个日期并尝试更改其颜色。当我安慰选定的日期时,我得到了选定的日期。但我无法改变它的颜色。任何帮助都非常感谢。以下是我的代码
日历.js
selectDate(day) {
let selectedDate = day.dateString;
if (this.state.dates[selectedDate]) {
const newDates = this.state.dates;
delete newDates[selectedDate]
this.setState({ dates: newDates });
} else {
const newDates = this.state.dates;
newDates[selectedDate] = [
{ selected: true, startingDay: true, color: '#05A081' },
{ selected: true, endingDay: true, color: '#05A081' },
]
this.setState({ dates: newDates });
console.log("NEW_ARRAY", this.state.dates);
}
}
....
<CalendarList
minDate={Date.now()}
pastScrollRange={24}
futureScrollRange={24}
markingType={'period'}
onDayPress={(day) => this.selectDate(day)}
markedDates={this.state.dates}
/>
以下是控制台结果
NEW_ARRAY
{2019-09-03: Array(2), 2019-09-04: Array(2), 2019-09-05: Array(2)}
2019-09-03: Array(2)
0: {selected: true, startingDay: true, color: "#05A081"}
1: {selected: true, endingDay: true, color: "#05A081"}
length: 2
2019-09-04: (2) [{…}, {…}]
2019-09-05: (2) [{…}, {…}]