No Callback after SQLite-Request

烈酒焚心 提交于 2019-12-20 03:23:06

问题


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 ;)


回答1:


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..


来源:https://stackoverflow.com/questions/5900156/no-callback-after-sqlite-request

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!