【发布时间】:2017-06-08 09:19:02
【问题描述】:
我正在使用 Rails 和 FullCalendar Scheduler,我希望能够在添加新对象时更新作为资源提供的 JSON 对象。
这是我的日历选项的简化版本:
fullcalendar-settings.js
$(document).ready(function() {
$('#calendar').fullCalendar({
header: {
left: 'promptResource, prev, next, today',
center: 'title',
right: 'agendaWeek, timelineDay'
},
customButtons: {
promptResource: {
text: '+ maker',
click: function() {
var name = prompt('Name');
if (name) {
$('#calendar').fullCalendar(
'addResource', { title: name }, true // scroll to the new source?
);
}
}
}
},
defaultView: 'timelineDay',
defaultDate: moment(),
editable: true,
resourceColumns: [
{
labelText: 'Client',
field: 'title'
}
],
resources: 'scheduler.json',
events: []
});
});
scheduler.json
[
{ "id": "1", "title": "LE" },
{ "id": "2", "title": "DB" },
{ "id": "3", "title": "VB" },
{ "id": "7", "title": "RL" }
]
资源是从“scheduler.json”加载的,我有一个按钮,您可以使用它添加新资源,但它现在只是临时的,在重新加载时会消失。
所以我的问题是当我添加新资源时如何更新“scheduler.json”中的 JSON 对象?
提前致谢
【问题讨论】:
-
在日历中创建事件后,您必须发送一个 ajax 请求以更新您的数据库,这将在您下次重新加载页面时生成 scheduler.json 文件。
-
我对 JSON 没问题,但不确定如何执行此类请求。
标签: javascript ruby-on-rails json fullcalendar fullcalendar-scheduler