我在日历上显示约会。我希望在活动中添加一个类,以便根据约会的状态更改背景颜色。
<script>
$(document).ready(function(){
var user_id = '<%= params[:id] %>';
var eventsPath = "/users/" + user_id + "/appointments.json";
$('#calendar').fullCalendar({
editable: false,
handleWindowResize: true,
displayEventEnd: false,
firstDay: 1,
allDaySlot: false,
columnFormat: 'ddd',
scrollTime: '12:00:00',
eventBackgroundColor: '#505B75',
eventBorderColor: '#505B75',
header: {
left: 'prev,next today',
center: 'title',
right: 'month,agendaWeek,agendaDay'
},
defaultView: 'agendaWeek',
height: 650,
slotDuration: "00:15:00",
slotEventOverlap: false,
loading: function(bool){
if (bool)
$('#loading').show();
else
$('#loading').hide();
},
events: eventsPath,
allDay: false,
});
});
</script>
这里是事件路径(JSON)
json.array! User.find(params[:user_id]).appointments do |appointment|
json.extract! appointment, :id, :business_title
json.title appointment.business_title
json.start appointment.starts_at
json.className 'boobs'
json.end appointment.starts_at + 30.minutes
json.url appointment_url(appointment, format: :html)
end
答案 0 :(得分:0)
您可以通过eventRender回调为特定事件添加样式。事件已经呈现,因此您需要更改样式/直接向元素添加类。
$('#calendar').fullCalendar({
...
eventRender: eventRenderCallback,
...
});
function eventRenderCallback(event, element){
element.addClass(event.className);
}
<style>
.myClass{
background-color:red !important;
}
</style>