有经验的人可以帮助我。我有这样的问题。如果items.tasks.person_id
等于items.people.id
事件应该有颜色people.color
。
如何根据分配给人员的颜色更改事件的颜色?事件有一个人 id,人对象有一个颜色。
示例items.tasks.person_id (123)
===items.people.id (123)
事件应该有颜色items.people.color (# e31e24)
此处代码:https ://stackblitz.com/edit/react-v71fhc
class App extends Component {
constructor() {
super();
this.state = {
events: []
};
}
componentDidMount() {
let appointments = {
"items": {
"tasks": [
{
"id": "1",
"person_id": "123",
'title': 'Some Event',
'start': new Date(2019, 7, 28, 0, 0, 0),
'end': new Date(2019, 7, 28, 0, 0, 0)
},
{
"id": "2",
"person_id": "456",
'title': 'DTS ENDS',
'start': new Date(2019, 7, 28, 0, 0, 0),
'end': new Date(2019, 7, 28, 0, 0, 0)
}
],
"people": [
{
"id": "456",
"color": "#5cb85c"
},
{
"id": "123",
"color": "#e31e24"
}
]
}
}
let appoint = appointments.items.tasks
console.log(appoint)
for (let i = 0; i < appoint.length; i++) {
appoint[i].id = appoint[i].id;
appoint[i].title = appoint[i].title;
appoint[i].start = moment.utc(appoint[i].start).toDate();
appoint[i].end = moment.utc(appoint[i].end).toDate();
}
this.setState({
events:appoint
})
}
render() {
return (
<div>
<Calendar
localizer={localizer}
events={this.state.events}
startAccessor="start"
endAccessor="end"
defaultView="week"
defaultDate={moment().toDate()}
/>
</div>
);
}
}