我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) [{…}, {…}]
DIEA
天涯尽头无女友
相关分类