早上好, 我使用下拉菜单选择了哪些事件'用户我必须在日历中显示。事件从数据库加载到文件JsonEvents.txt。 当我从下拉列表中更改用户并单击自定义按钮以显示新事件时,日历不会加载事件。只有等待一秒钟然后单击按钮,在这种情况下,日历才会显示更正事件。问题是什么?为什么日历不会立即显示新事件?提前谢谢。
这是javascript代码:
<script type='text/javascript'>
$(document).ready(function() {
var calendar = $('#calendar').fullCalendar({
lang: 'it',
customButtons: {
myCustomButton: {
text: 'Visualizza',
click: function() {
$("#calendar").fullCalendar('refetchEvents');
}
}
},
header: {
left: 'prev,next today myCustomButton',
center: 'title',
right: 'month,agendaWeek,agendaDay'
},
lazyFetching: false,
selectable: true,
select: function(start, end, allDay) {
var title = prompt('Nome evento:');
if (title) {
if(end.hasTime()){
var st = moment(start).format('YYYY-MM-DD HH:mm:ss');
var en = moment(end).format('YYYY-MM-DD HH:mm:ss');
createEvent(title,st,en,false);
calendar.fullCalendar('unselect');
}
else{
var st = moment(start).format('YYYY-MM-DD');
createEvent(title,st,'',true);
calendar.fullCalendar('unselect');
}
}
},
editable: true,
eventClick: function(event, element) {
$('#finestra').dialog({
modal: true,
buttons: {
"Si": function() {
deleteEvent(event.id);
calendar.fullCalendar( 'removeEvents' , event.id);
$( this ).dialog( "close" );
},
"No": function(){
$( this ).dialog( "close" );
var title = prompt('Nome evento:',event.title);
event.title = title;
updateEvent(event.id,event.title,'','');
calendar.fullCalendar('updateEvent', event);
}
}
});
},
eventResize: function (event, dayDelta, minuteDelta, revertFunc) {
if (confirm("Confermi di modificare l'orario dell'evento?")) {
var st = moment(event.start).format('YYYY-MM-DD HH:mm:ss');
var en = moment(event.end).format('YYYY-MM-DD HH:mm:ss');
updateEvent(event.id, event.title, st, en );
}
else {
revertFunc();
}
},
eventDrop: function(event, delta, revertFunc) {
if (confirm("Confermi di modificare la data dell'evento?")) {
var st = moment(event.start).format('YYYY-MM-DD HH:mm:ss');
var en = moment(event.end).format('YYYY-MM-DD HH:mm:ss');
updateEvent(event.id, event.title, st, en );
}
else {
revertFunc();
}
},
events: {
url: "JsonEvents.txt",
}
});
});
</script>
下拉列表是在jsp代码中创建的:
<form action="../AgendaServlet" method="post" id="frm_age" >
<table>
<tr>
<td class="row">
<span class="small_label">Select user</span>
</td><td class="row s230" align="right">
<select class="custom-select s230" id="specialista" name="specialista" onchange="viewEvents()">
<% list = (List<KeyValueString>) session.getAttribute(Def.list_specialisti);
if (list != null) {
for (KeyValueString kv : list) { %>
<option value="<%=kv.getKey() %>" ><%=kv.getValue() %></option>
<% }
} %>
</select>
</td>
</tr>
</table>
<div id='calendar'></div>
</form>
jsp代码工作正常。我认为问题出在javascript代码中。