0

在我的完整日历页面中,我有一个(默认)事件源区域,如下所示:

eventSources: [{
    url: '/events/index/',
    color: 'yellow',
    textColor: 'black',
    ignoreTimezone: false
}],

我有一个名为"rentalcars". 我将如何使事件自动从该模型中提取?这个模型有开始和结束日期。

我试过了:

eventSources: [{
    url: '/rentalcars/index/',
    color: 'yellow',
    textColor: 'black',
    ignoreTimezone: false
}],

这当然行不通。我查看了 arshaw 的源代码,我知道如何制作静态事件,但我正在寻找动态事件:将迭代现有模型的事件。

有什么建议么?

4

1 回答 1

1

您的 url 参数需要返回 FullCalendar 可以理解和解析的任何内容,因此根据文档判断,您必须确保您的rentelcars索引操作返回此特定格式:

{
        title  : 'event1',
        start  : '2010-01-01'
    },
    {
        title  : 'event2',
        start  : '2010-01-05',
        end    : '2010-01-07'
    },
    {
        title  : 'event3',
        start  : '2010-01-09 12:30:00',
        allDay : false // will make the time show
    }
}

因此,在您rentalcars_controller.rbindex定义中,您必须确保返回这种对我来说很像 JSON 的格式。因此,最简单的方法是将其作为您的 JavaScript:

eventSources: [{
  url: '/rentalcars.json',
  color: 'yellow',
  textColor: 'black',
  ignoreTimezone: false
}],

然后在您的控制器中,您将拥有如下内容:

def index
    rentalcar_dates = RentelcarDates.all # assuming this is an object that holds start, end date and maybe the car name

    respond_to do |format|
        format.html
        format.json { render :json => rentalcar_dates }
    end
end
于 2013-08-13T20:17:07.343 回答