Max*_*tiy 17 javascript calendar reactjs
我需要制作一个包含事件的日历,我决定使用react-big-calendar.但我需要制作不同颜色的活动.因此每个事件都有一些类别,每个类别都有相应的颜色.如何通过反应改变事件的颜色?
Max*_*tiy 46
对不起,我还没有很好地阅读文档.它可以在eventPropGetter
属性的帮助下完成.我做到了这样:
eventStyleGetter: function(event, start, end, isSelected) {
console.log(event);
var backgroundColor = '#' + event.hexColor;
var style = {
backgroundColor: backgroundColor,
borderRadius: '0px',
opacity: 0.8,
color: 'black',
border: '0px',
display: 'block'
};
return {
style: style
};
},
render: function () {
return (
<Layout active="plan" title="Planning">
<div className="content-app fixed-header">
<div className="app-body">
<div className="box">
<BigCalendar
events={this.events}
defaultDate={new Date()}
defaultView='week'
views={[]}
onSelectSlot={(this.slotSelected)}
onSelectEvent={(this.eventSelected)}
eventPropGetter={(this.eventStyleGetter)}
/>
</div>
</div>
</div>
</Layout>
);
}
Run Code Online (Sandbox Code Playgroud)
Ouc*_*cam 10
关于如何设置不同类型事件样式的附加提示:在myEvents
事件对象数组中,我给每个对象一个布尔属性isMine
,然后我定义了:
<BigCalendar
// other props here
eventPropGetter={
(event, start, end, isSelected) => {
let newStyle = {
backgroundColor: "lightgrey",
color: 'black',
borderRadius: "0px",
border: "none"
};
if (event.isMine){
newStyle.backgroundColor = "lightgreen"
}
return {
className: "",
style: newStyle
};
}
}
/>
Run Code Online (Sandbox Code Playgroud)
这个解决方案很简单!
eventPropGetter={(event) => {
const backgroundColor = event.allday ? 'yellow' : 'blue';
return { style: { backgroundColor } }
}}
Run Code Online (Sandbox Code Playgroud)
根据您的需要更改条件即可完成。
归档时间: |
|
查看次数: |
12657 次 |
最近记录: |