1

I need to display more text in the fullcalander. but the problem is i am getting data from the mySQL db as json data through ajax call. so i dont know the exact length of data which is coming. so i need to show the daily events in the fullcalendar dynamically in a loop. the following code i tried but i didnt got the output. can anyone help me. thanx in advance

var testJson = ['value1', 'value2'];
$('#full_calendar').fullCalendar({
    header: {
        left: 'prev,next today',
        center: 'title',
        right: 'month,agendaWeek,agendaDay'
    },
    editable: true,
    events: [
        for(var i=0;i<2;i++){
            {
                title: ''+testJson [i],
                start: new Date(y, m, 3)
            }
    } ]
});
4

2 回答 2

2

先做两件事:当你想知道接收数据的确切长度时......为什么不在 JSON 对象中发送它们呢?

例如

var test = {"data":[1,2,3,4,5],"size":5}

获得 lentgh 的第二种方法是长度字段。每个 javascript 对象都有一个长度字段。在上面的示例中,test.data.length 将返回 5(就像 test.size 一样)。

而且我很确定您不能在数组声明中运行迭代,因此只需构建数组之前:

var events = [];
$(test).each(function(i, obj) {
    events[] = {title: test.data[i], start: new Date(y, m, 3)}
}

没有 jquery 它会是这样的:

var size = test.data.length;
var events = [];
for(var i =0; i < size; i++) {
    events[] = {title: test.data[i], start: new Date(y, m, 3)}
}

然后将其传递给您的函数调用

$('#full_calendar').fullCalendar({
    header: {
        left: 'prev,next today',
        center: 'title',
        right: 'month,agendaWeek,agendaDay'
    },
    editable: true,
    events: events
});
于 2013-01-18T15:46:16.097 回答
0

If you use ajax call for getting data then you must write 'events: "addres for ajax request"' and add a file for ajax request. E.g. add file 'json-events.php' in the root of site, in the parametr events: 'json-events.php'. In the json-events.php you do query to the database, and get event data in array, where one event - one data array (the array in the array). Every event must have id, title, start, like:

array( array(
'id' => event id,
'title' => event title,
'start' => YYYY-mm-dd,
'end' => YYYY-mm-dd
))

After that convert to json format (json_encode()) and echo

于 2013-01-22T08:00:38.707 回答