Udo
Udo

Reputation: 21

No Callback after SQLite-Request

awesome plugin. But I tried to load some events via SQL-Rquest. The Request is successfully, I can put the Array in another Container or alert them, but the Calendar wouldnt load the events. Here my Script

        $('#calendar').fullCalendar(
            {
             header: {
                    left: 'prev,next today',
                    center: 'title',
                    right: 'month,agendaWeek,agendaDay'
                    },
             editable: true,        
             events: function(start, end, callback)
                        {
                        var rs = db.execute("select * from xCal");
                        var i = 0;
                        var events = '[';
                        while(rs.isValidRow()) 
                            {                       
                            if(i == 0){var events=events}else{events = events+','}
                            events=events+
                                        "{id:'"+rs.fieldByName('id')+"',"+
                                        "title:'"+rs.fieldByName('title')+"',"+
                                        "allDay:'"+rs.fieldByName('allDay')+"',"+
                                        "start:'"+rs.fieldByName('start')+"',"+
                                        "end:'"+rs.fieldByName('end')+"',"+
                                        "url:'"+rs.fieldByName('url')+"',"+
                                        "description:'"+rs.fieldByName('description')+"'}";
                            i++;
                            rs.next(); 
                            }
                        events = events+']';
                        callback( events );

                        }

            }); 

Udate cause comments .....

Thanks for replaying, but thats not the reason. I changed the code (removed quotes and the url complete), but it´s not running :( .

If I try to put the return of SQL request in the event-option, its runnig perfect. It seems, I have a problem with the callback();.

I have alerted the callback-var.

function(events){
            callback(events);
            popLoading();
            }

Calls callback itself?

Update cause answer ....

See above. Believe me, the string is correct. BTW I´m using Unix timestamp ;)

Upvotes: 2

Views: 693

Answers (1)

Piotr Kula
Piotr Kula

Reputation: 9841

So if you use

 events: function(start, end, callback) { }

to make your events you have to create a jscript array .. not a json type string.

So as a basic and simple example that works.

events:function(start,end,callback)
        {
            var event = [];
            event.push({
                title: 'Garten',
                start: '2011-05-10T00:00:00',
                allday: true
            });

            callback(event);
        }

On it works as this example shows

http://jsfiddle.net/ppumkin/6wE8v/

You just need to plug your db stuff in. Apologies for the confusion in the comments

so a bit of your code:

id: rs.fieldByName('id'),
title: rs.fieldByName('title'),
start: rs.fieldByName('start'),
etc..

Upvotes: 0

Related Questions