【问题标题】:Full Calendar - Rails - Adding Custom CSS Classes to Events完整日历 - Rails - 向事件添加自定义 CSS 类
【发布时间】:2015-07-09 15:36:40
【问题描述】:

我正在日历上显示约会。我希望为事件添加一个类,以便我可以根据约会的状态更改它们的背景颜色。

<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

【问题讨论】:

  • 问题是什么?

标签: javascript ruby-on-rails json fullcalendar


【解决方案1】:

您可以通过 eventRender 回调为特定事件添加样式。该事件已经呈现,因此您需要更改样式/直接向元素添加一个类。

$('#calendar').fullCalendar({
    ...
    eventRender: eventRenderCallback,
    ...
});

function eventRenderCallback(event, element){
    element.addClass(event.className);
}

<style>
    .myClass{
        background-color:red !important;
    }
</style>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多