gpt4 book ai didi

javascript - Fullcalendar Rails 上的 Popover Bootstrap

转载 作者:行者123 更新时间:2023-11-30 07:42:25 24 4
gpt4 key购买 nike

Fullcalendar 非常漂亮。我试试我想尝试在每个事件上添加弹出窗口作为描述。如果我单击一个事件,则会显示弹出窗口。例如http://i.cubeupload.com/LuBXjx.png我不了解 json 和 javascript,但我想了解这一切。谁能帮帮我?

Popover日历.js.咖啡

$(document).ready ->
$('#test').fullCalendar
header:
left: 'prev,next today',
center: 'title',
right: 'month'
defaultView: 'month',
height: 500,



buttonText: {
month: 'month',
today: 'today'
},

eventSources: [{
url: '/school/calendars',
}],


firstHour: 6,
slotMinutes: 30,
defaultEventMinutes: 120,
axisFormat: 'H',
timeFormat: 'H(:mm)',
dragOpacity: {
agenda: 0.5
},
minTime: 0,
maxTime: 24

在模型/event.rb 上

scope :between, lambda {|start_time, end_time|
{:conditions => [
"starts_at > ? and starts_at < ?",
Event.format_date(start_time), Event.format_date(end_time)
] }
}

# 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.name ,
:description => self.description || "",
:start => starts_at.rfc822,
:end => ends_at.rfc822,
:allDay => self.all_day,
:recurring => false,
#:color => "red"
}

end

def self.format_date(date_time)
Time.at(date_time.to_i).to_formatted_s(:db)
end

在 controller/school/calendars_controller.rb 上

@events = Event.scoped
@events = Event.between(params['start'], params['end']) if (params['start'] && params['end'])
respond_to do |format|
format.html # index.html.erb
format.json { render json: @events }
end

这是弹窗

<div class="popover right">
<div class="arrow"></div>
<h3 class="popover-title"> <%= @event.nama %> </h3>
<div class="popover-content">
<p>Start at : <%= @event.starts_at %>
End at : <%= @event.ends_at %>
Description : <%= @event.description %>
<br/>
</p>
</div>
</div>

最佳答案

您需要的是 eventRender回调,它允许您操作每个事件。

$('#calendar').fullCalendar({
...
eventRender: function (event, element) {
element.popover({
title: event.nama,
placement: 'right',
content: + '<br />Start: ' + event.starts_at + '<br />End: ' + event.ends_at + '<br />Description: ' + event.description,
});
}
});

关于javascript - Fullcalendar Rails 上的 Popover Bootstrap,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13904033/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com