首页 文章

如何在fullcalendar中为事件设置JSON值?

提问于
浏览
0

我有一个包含JSP中对象的arraylist的JSON字符串 .

values=gson.toJson(list);%>
<input type="hidden" id="var1" value='<%=values%>'>

'values'中的JSON字符串根据fullcalendar格式化为正确的名称

[{“title”:“Aaron at 101”,“start”:“2016-11-30”,“end”:“2016-12-05”},{“title”:“Dave at 103”,“start” “:” 2016年11月25" 日, “结束”: “2016年12月3日”}]

当我尝试在fullcalendar中使用此变量时,我只看到一个空日历 .

$(document).ready(function() {
        var lists= $('#var1').val();
        $('#calendar').fullCalendar({
            defaultDate: '2016-12-01',
            editable: true,
            eventLimit: true,
            events: lists
        });

    });

是否有适当的方式来分配事件?请帮帮我,因为我是jQuery的新手 .

1 回答

  • 1

    你是否添加了moment.js依赖?

    Bellow我根据你的例子写了一个工作片段 .

    var events = [
      {
        "title":"Aaron at 101",
        "start":"2016-11-30",
        "end":"2016-12-05"
      },
      {
        "title":"Dave at 103",
        "start":"2016-11-25",
        "end":"2016-12-03"
      }
    ];
    
    $('#calendar').fullCalendar({
        defaultDate: '2016-12-01',
        editable: true,
        eventLimit: true,
        events: events
    });
    
    <!-- fullcalendar dependencies -->
    <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.17.0/moment.min.js"></script>
    
    <!-- fullcalendar script -->
    <script src="https://cdnjs.cloudflare.com/ajax/libs/fullcalendar/3.0.1/fullcalendar.min.js"></script>
    
    <!-- fullcalendar style -->
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/fullcalendar/3.0.1/fullcalendar.min.css">
    
    <div id="calendar"></div>
    

相关问题