【发布时间】:2017-09-19 17:53:33
【问题描述】:
我是使用 fullcalendar 的新手,我不知道如何将 json 请求转为在日历上绘图
我的模型,而不是使用标题、开始、结束和全天
改为使用 name、start_date、completion_date、all_day
因此日历不会将我模型中的对象渲染到完整日历上
我的views.py是
def view_calendar(request):
jobs = Job.objects.all()
return HttpResponse(events_to_json(jobs), content_type='application/json')
这正在生成一个显示为
的 JSON 对象[{"completionDate": "2015-11-06", "startDate": "2015-11-06", "allDay": false, "name": "342345", "id": 7}, {"completionDate": "2017-04-30", "startDate": "2017-02-19", "allDay": false, "name": "Calendars", "id": 9},
{"completionDate": "2015-02-28", "startDate": "2015-02-26", "allDay": false, "name": "Lowe's Remodel ", "id": 4}, {"completionDate": "2015-02-04", "startDate": "2015-01-18", "allDay": false, "name": "Lowe's Remodel 2", "id": 1},
{"completionDate": "2015-09-13", "startDate": "2015-05-13", "allDay": false, "name": "Lowe's Remodel 3", "id": 5}, {"completionDate": "2017-04-30", "startDate": "2017-04-21", "allDay": false, "name": "WONDER", "id": 10},
{"completionDate": "2015-09-03", "startDate": "2015-08-03", "allDay": false, "name": "aaa gfdsgfs dgfgsd daaa gfdsgfs dgfgsd daaa gfdsgfs dgfgsd daaa gfdsgfs dgfgsd d", "id": 6},
{"completionDate": "2016-04-22", "startDate": "2015-02-24", "allDay": false, "name": "dgfs3344", "id": 3},
{"completionDate": "2015-02-26", "startDate": "2015-02-01", "allDay": false, "name": "gfdgdfs", "id": 2},
{"completionDate": "2015-11-06", "startDate": "2015-11-06", "allDay": false, "name": "ssssgf", "id": 8}]
我不知道如何将此对象渲染到全日历上,因为即使使用此 json,它似乎也不接受这些参数
我很欣赏这些答案,但我没有澄清,我已经将我的模型解析为全日历格式
`return HttpResponse(events_to_json(jobs).replace('name', 'title').replace("startDate", "start").replace('completionDate', 'end'), content_type='application/json')`
在 Django 中,这会呈现一个 url /output/ 转储所有这些值,例如
[{"end": "2015-11-06", "start": "2015-11-06", "title": "342345"}, {"end": "2015-02-28", "start": "2015-02-26", "title": "Lowe's Remodel "}, {"end": "2015-02-04", "start": "2015-01-18", "title": "Lowe's Remodel 2"}, {"end": "2015-09-13", "start": "2015-05-13", "title": "Lowe's Remodel 3"}, {"end": "2015-09-03", "start": "2015-08-03", "title": "aaa gfdsgfs dgfgsd daaa gfdsgfs dgfgsd daaa gfdsgfs dgfgsd daaa gfdsgfs dgfgsd d"}, {"end": "2016-04-22", "start": "2015-02-24", "title": "dgfs3344"}, {"end": "2015-02-26", "start": "2015-02-01", "title": "gfdgdfs"}, {"end": "2015-11-06", "start": "2015-11-06", "title": "ssssgf"}]
我的问题是如何将这个包含准备使用的 json 格式的 url 返回到我的 Fullcalendar 事件中:?
【问题讨论】:
标签: javascript json django xmlhttprequest fullcalendar