如何添加事件源 [英] How to add event sources

查看:146
本文介绍了如何添加事件源的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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

我有一个名为rentalcars的模型(和视图)文件夹。我将如何使这些事件自动从该模型中拉出来?

这个模型有开始日期和结束日期。 eventSources:[{
url:'/ rentalcars / index /',
color:'yellow',
textColor:'black',
ignoreTimezone:false
} ],

这当然不起作用。我查看了arshaw的源代码,并且我可以告诉如何创建静态事件,但我正在寻找动态的:可以遍历现有模型的动态的。



有什么建议吗?

解决方案

您的url参数需要返回FullCalendar可以解析的任何内容,因此可以通过 documentation ,您必须确保您的 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 //将使时间显示
}
}

因此,在您的 rentalcars_controller.rb 索引的定义,你将不得不确保你返回这个看起来很像JSON的格式。所以,最简单的方法就是将它作为你的JavaScript:

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

然后在你的控制器中你会有这样的东西:

  def index 
rentalcar_dates = RentelcarDates.all#假设这是一个包含开始,结束日期和汽车名称的对象

respond_to do | format |
format.html
format.json {render:json => rentalcar_dates}
结束
结束


In my fullcalendar page, I have a (default) event sources area that looks like such:

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

I have a model (and view) folder titled "rentalcars". How would I make the events automatically be pulled from that model? This model has start and end dates.

I tried:

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

which certainly does not work. I looked at arshaw's source, and I can tell how to make static events, but I am looking for dynamic ones: ones that will iterate through existing models.

Any suggestions?

解决方案

Your url parameter needs to return whatever the FullCalendar understands and can parse, so judging by the documentation you will have to make sure that your rentelcars index action returns this particular format:

{
        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
    }
}

So in your rentalcars_controller.rb in the index definition you will have to make sure that you return this format which looks a lot like JSON to me. So, easiest way would be to have this as your JavaScript:

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

And then in your controller you will have something like this:

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

这篇关于如何添加事件源的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆