0

我在 rails 应用程序中使用 jquery fullcalendar。目前它在月份显示中显示 event.title 字段。我希望它也显示和附加字段 = workorder.wonum

我在 Stackoverflow 上找到了这个解决方案。

eventRender: (event, element) ->
  element.find(".fc-event-title").html(event.title + ": <span>" + event.workorder.wonum + "</span>")

该代码显示 event.title,然后显示“未定义”。如果我将 event.workorder.wonum 更改为 event.description --> 就可以了。

我可以通过更改创建 json 的控制器中的 event.title 来做到这一点吗?

像这样的东西(它不起作用):

respond_to do |format|
  format.json { render json: @events, :only => [:title => :title + :workworder.wonum] }
end

谢谢!!

4

1 回答 1

1

我终于弄明白了。

解决方案是将 workorder.wonum 与标题结合起来:

 # need to override the json view to return what full_calendar is expecting.
 # http://arshaw.com/fullcalendar/docs/event_data/Event_Object/
 def as_json(options = {})
  {
    :id => self.id,
    :title => "#{self.workorder.wonum} #{self.title}",
    :description => self.description || "",
    :start => starts_at.rfc822,
    :end => ends_at.rfc822,
    :allDay => self.all_day,
    :recurring => false,
    :url => Rails.application.routes.url_helpers.event_path(id),
    :color => "blue",
    :backgroundColor => "blue",
    :borderColor => "black",
    :textColor  => "white"
 }

end
于 2013-01-25T00:08:20.707 回答