簡體   English   中英

Rails Fullcalendar將某些事件設置為可編輯

[英]Rails Fullcalendar set certain events editable

我在Rails中使用Fullcalendar。 事件模型中的以下代碼為Fullcalendar事件創建json。

我希望事件可編輯:如果event.maxsynch =“ N”,則為true

這是代碼:

def as_json(options = {})
  {
      :id => self.id,
      :title => "#{self.workorder.wonum} #{self.title} #{self.hours}",
      :description => self.description || "",
      :start => starts_at.rfc822,
      :end => ends_at.rfc822,
      :allDay => self.all_day,
      :recurring => false,
      :editable => false if self.maxsynch == "N" :true,
      :url => Rails.application.routes.url_helpers.event_path(id),
      :color => "blue",
      :backgroundColor => "blue",
     :borderColor => "black",
     :textColor  => "white"
  }

end

如果self.maxsynch ==“ N”:true,則行:editable => false是錯誤的。

我該如何解決?

謝謝您的幫助!!

如果我正確理解了您的問題,那么您嘗試使用的稱為條件運算符或三元運算符。 “如果條件成立,則執行A,否則執行B。”

您可以在這里閱讀有關此內容的更多信息: http : //en.wikipedia.org/wiki/%3F : #Ruby

因此該行應顯示為

:editable => (self.maxsynch == "N" ? true : false),

但是,如果您要做的只是返回true或false,則完全不必使用條件運算符。 您只需要傳遞評估的表達式即可。

:editable => (self.maxsynch == "N"),

如果語句為true,則返回true,否則返回false。 如果您需要它具有相反的行為,只需添加一個! 到語句的開頭,它將顛倒邏輯。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM