簡體   English   中英

javascript函數中的JSTL c標簽

[英]JSTL c tag in javascript function

我正在嘗試使用spring mvc集成jquery fullcalendar和mysql。 我必須從mySql加載計划數據並將日期設置為日歷。 請顯示此:

<script type='text/javascript'>
            $(document).ready(function() {
                var calendar;
                var date = new Date();
                var y = date.getFullYear();
                var m = date.getMonth();
                var d = date.getDate();

                $('#calendar').fullCalendar({
                    header : {
                        left : 'title,prev,next today',
                        center : '',
                        right : 'month,agendaWeek,agendaDay' 
                    },
                    height: 650,
                    selectable: true,
                    select: function(start, end, allDay) {
                        var title = prompt('Event Title:');
                        if (title) {
                            calendar.fullCalendar('renderEvent',
                            {
                                title: title,
                                start: start,
                                allDay: allDay
                            },
                                    true // make the event "stick"
                                    );
                        }
                        calendar.fullCalendar('unselect');
                    },
                    editable : true,

                  events: [
                     <c:forEach var='event' items='${myData.events}'>
                         { title: '${event.title}', start: new Date (${event.timestamp}) },
                     </c:forEach>
      null // the trailling comma is  avoid the stray trailing comma.

    ];
                });

            });
        </script>

這樣...有可能嗎? 如果是這樣,如何使用? 和要將fullcalendar與DB集成,我是否只需要使用php feed和Json,Ajax? 請幫我。

如果您使用像GSON這樣的庫,就可以簡化事情

在您的控制器中使用以下代碼

    String jsonString = new Gson().toJson(ObjectList); // ObjectList is list of event object
    System.out.println(jsonString);
    request.setAttribute("eventsJson",jsonString); //setting  jsonString to request scope.

在JSP中

events: ${eventsJson}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM