开发者

Full Calendar: Adding time to the calendar's json

I've been using fullCalendar for a while and getting data via json. there is a sample listed below.

[{"id":2,"name":"1","title":"takvim","start":"2009-11-04","end":"2009-11-04"}]

It works fine but I upgraded the new version of the calendar and it has agenda-week view. I need to use grid area(hours there) on agenda-week so my json must be like this.

[{"id":2,"name":"1","title":"takvim","start":"2009-11-04 12:30:00","end":"2009-11-04 13:30:00"}]

In addition if I used the data as static I could use it like this

{
title: 'Meeting',
start: new Date(y, m, d, 开发者_运维问答10, 30),
allDay: false
}

Unfortunately there is no data to appear when I add time. How do I solve it?


Your code is okey but I should point out that there is no way to reach the json's code to hour:min values. At least i couldn't handle it. Basicly how javascript Date object works?

var $date = new Date(Year,months,day,hour,min,sec) and  in calendar works like this

{
                title: 'Lunch',
                start: new Date(y, m, d, 12, 0),
                end: new Date(y, m, d, 14, 0),
                allDay: false
            },

so you should split your values then can obtain every date object. Also you should change your json code like this.

[{"id":"1","title":"piman","start":"2009-11-04-00:00:00","end":"2009-11-04-16:00:00"}]

There may be easier way but as you know documentation is so poor. But it works fine that style you may want to use it...

Cheers


I solved the problem. Firstly I've taken some code from here and changed it. I'm showing it below...

events: function(start, end, callback) {

    // do some asynchronous ajax
    $.getJSON("aj_calendar_json.asp?rndtime="+new Date().getTime()+"&baseID=<%=baseId%>&depId=<%=depId%>",
            {
                    start: start.getTime(),
                    end: end.getTime()
            },
            function(result) {

                    if(result != null){

                        for (i in result) {

                            var calEvent = result[i];

                            var $startNew   = calEvent.start.split("-")
                                $sNewYear   = parseInt($startNew[0])
                                $sNewMonth  = (parseInt($startNew[1])-1)
                                $sNewDay    = parseInt($startNew[2])
                                $sNewTime   = $.trim($startNew[3])

                                if ( $sNewTime != "" ){
                                    $splitNewTime   = $sNewTime.split(":")
                                    $sNewTimeHour   = $splitNewTime[0]
                                    $sNewTimeMin    = $splitNewTime[1]
                                }
                                else{
                                    $sNewTimeHour   = 0
                                    $sNewTimeMin    = 0
                                }                                                                                       

                            var $endNew     = calEvent.end.split("-")
                                $eNewYear   = parseInt($endNew[0])
                                $eNewMonth  = (parseInt($endNew[1])-1)
                                $eNewDay    = parseInt($endNew[2])
                                $eNewTime   = $.trim($endNew[3])

                                if ( $eNewTime != "" ){
                                    $splitNewTime   = $eNewTime.split(":")
                                    $eNewTimeHour   = $splitNewTime[0]
                                    $eNewTimeMin    = $splitNewTime[1]
                                }
                                else{
                                    $eNewTimeHour   = 0
                                    $eNewTimeMin    = 0
                                }                                                                                                                                                                               

                            calEvent.start  = new Date( $sNewYear , $sNewMonth , $sNewDay , $sNewTimeHour , $sNewTimeMin )
                            calEvent.end    = new Date( $eNewYear , $eNewMonth , $eNewDay , $eNewTimeHour , $eNewTimeMin )

                            sNewGetTime     = new Date( $sNewYear , $sNewMonth , $sNewDay)
                            eNewGetTime     = new Date( $eNewYear , $eNewMonth , $eNewDay)

                            if ( sNewGetTime.getTime() == eNewGetTime.getTime() ){ 
                                calEvent.allDay = false
                            }

                        }
                    }

                    var calevents = result;

                    // then, pass the CalEvent array to the callback
                    callback(calevents);

            });

}

It may look complicated, but it works fine. If you have any problem please ask me...


im also having this problem but i found an easier solution in php json try the following code

$startdate='Nov 11 2009 10:10:00';

$enddate='Nov 11 2009 12:10:00';

then in your array

'start' => "$startdate",
'end' => "$enddate",

and that's it

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜