1
我正在使用FullCalendar插件来显示来自我的数据库的事件。我将事件存储在实例变量中,并将其显示在View中。用户可以从下拉菜单中选择一个选项,根据该选项,事件将被过滤。问题是我不能做那个过滤。我正在尝试几天。过滤FullCalendar事件
这是我的根 '家' 景观:
<script type="text/javascript">$(document).ready(function() {
setCalendar(<%= @doctors.first.id %>);
$("#doctor_id").change(function() {
var selectedVal = $(this).val();
setCalendar(selectedVal);
});
function setCalendar(doctor_id){
$.ajax({
type: 'GET',
url: "/appointments",
data: "doctor_id=" + doctor_id,
dataType: "json",
success: function(data) {
alert(data[0].id);
},
error: function(jqXHR, textStatus, errorThrown) {
console.log(textStatus);
console.log(errorThrown);
}
})
// page is now ready, initialize the calendar...
$('#calendar').fullCalendar({
editable: true,
disableResizing: true,
disableDragging: true,
events:
[
<% @appointments.each do |appointment| %>
{
id : "<%= appointment.id %>",
title : "Reserved",
start : "<%= appointment.start_date.in_time_zone.strftime '%Y-%m-%dT%H:%M:%S' %>",
end : "<%= appointment.end_date.in_time_zone.strftime '%Y-%m-%dT%H:%M:%S' %>",
allDay : false
},
<% end %>
],
...
控制器:
class StaticController < ApplicationController
def home
if params[:doctor_id]
@appointments = Appointment.where(doctor_id: params[:doctor_id])
else
@appointments = Appointment.all
end
@doctors = Doctor.all
end
end
我的路线:
root 'static#home'
match '/appointments', to: 'static#home', via: 'get'
的问题是,过滤器不能正常工作。实例变量'@appointments'总是包含所有事件,并且所有事件都显示在日历上。任何想法在这段代码中有什么错误?
谢谢。