有一种方法可以创建一个您想要从日期数组创建的对象,
选项正在使用
reduce
要将数组转换成一个对象,只需按照我使用纯javascript实现的代码操作
在NextDay数组中成功获取值后调用函数
constructor(props){
super(props);
this.state = {
marked: null,
};
}
componentDidMount() {
this.anotherFunc();
}
// call function after you successfully get value in nextDay array
anotherFunc = () => {
var obj = nextDay.reduce((c, v) => Object.assign(c, {[v]: {selected: true,marked: true}}), {});
this.setState({ marked : obj});
}
现在将此状态添加到日历元素中
<Calendar
...
markedDates={this.state.marked}
...
/>
查看
question
我也要同样的,所以