我正在尝试使用fullcalendar从我的数据库中呈现数据,当某些内容被删除时。我可以看到数据是由ajax正确传递的。但是当调用回调时,我收到错误消息 未捕获TypeError:对象不是函数 。
下面你找到我的代码:
drop: function (start, end, timezone, callback) {
var resource_id = $(this).attr('id');
var id = resource_id.substring(resource_id.lastIndexOf('_') + 1, resource_id.length);
var events_uri = '/get_resource_events';
$.ajax({
url: resource_base_url() + events_uri,
data: {
id: id
},
type: "GET",
dataType: 'json',
success: function(data) {
var events = [];
for (order in data) {
var allday_data = data[order].allday;
if (allday_data === 'true') {
allday_data = true;
} else {
allday_data = false;
};
events.push({
id: data[order].id,
title: [data[order].initials] + [data[order].last_name],
start: data[order].start,
end: data[order].end,
allDay: allday_data,
color: data[order].calendar_color
});
};
callback(events);
$('#calendar').fullCalendar('rerenderEvents');
}
});
}
有任何解决错误消息的消息吗?
低于ajax的结果,回调
[{"id":"136","initials":"M.H.","last_name":"Tjon-Sien-Fat","start":"2014-08-05 09:00:00","end":"2014-08-05 13:00:00","allday":null,"calendar_color":"#00ffff"},{"id":"138","initials":"M.H.","last_name":"Tjon-Sien-Fat","start":"2014-08-04 09:00:00","end":"2014-08-04 13:00:00","allday":null,"calendar_color":"#00ffff"},{"id":"139","initials":"M.H.","last_name":"Tjon-Sien-Fat","start":"2014-08-07 07:30:00","end":"2014-08-07 11:30:00","allday":null,"calendar_color":"#00ffff"},{"id":"142","initials":"M.H.","last_name":"Tjon-Sien-Fat","start":"2014-08-06 00:00:00","end":"0000-00-00 00:00:00","allday":null,"calendar_color":"#00ffff"},{"id":"143","initials":"M.H.","last_name":"Tjon-Sien-Fat","start":"2014-08-06 11:30:00","end":"2014-08-06 15:30:00","allday":null,"calendar_color":"#00ffff"},{"id":"155","initials":"M.H.","last_name":"Tjon-Sien-Fat","start":"2014-08-10 09:00:00","end":"2014-08-10 13:00:00","allday":null,"calendar_color":"#00ffff"},{"id":"170","initials":"M.H.","last_name":"Tjon-Sien-Fat","start":"2014-08-28 10:00:00","end":"2014-08-28 15:00:00","allday":null,"calendar_color":"#00ffff"},{"id":"171","initials":"M.H.","last_name":"Tjon-Sien-Fat","start":"2014-08-26 08:00:00","end":"2014-08-26 12:30:00","allday":null,"calendar_color":"#00ffff"},{"id":"175","initials":"M.H.","last_name":"Tjon-Sien-Fat","start":"2014-08-30 07:00:00","end":"2014-08-30 14:30:00","allday":null,"calendar_color":"#00ffff"},{"id":"183","initials":"M.H.","last_name":"Tjon-Sien-Fat","start":"2014-08-29 07:30:00","end":"2014-08-29 13:00:00","allday":null,"calendar_color":"#00ffff"}]
我尝试了您描述的解决方案,但我仍然收到相同的错误消息 对象不是函数 。您可以在下面找到完整的JS文件。还有其他任何建议吗?
$(document).ready(function() {
function resource_base_url() {
return base_url() + '/resource_controller/';
}
/* initialize the calendar
-----------------------------------------------------------------*/
$('#calendar').fullCalendar({
firstDay: 1, // Sunday=0, Monday=1, Tuesday=2, etc.
aspectRatio: 2.5,
eventTextColor: 'black',
theme: true, // false, true
handleWindowResize: true,
editable: true,
droppable: true, // this allows things to be dropped onto the calendar !!!
// Determines which icons are displayed in buttons of the header when theming is on.
themeButtonIcons:{ // Check http://api.jqueryui.com/theming/icons/ for avalible icon names
prev: 'ui-icon ui-icon-circle-triangle-w',
next: 'ui-icon ui-icon-circle-triangle-e'
},
header: {
left: 'prev,next today',
center: 'title',
right: 'month,agendaWeek,agendaDay'
},
//events: calendar_base_url() + '/events',
eventRender: function(event, element, view) {
if (event.allDay === 'true') {
event.allDay = true;
} else {
event.allDay = false;
}
},
drop: function (start, end, timezone, callback) {
var resource_id = $(this).attr('id');
var id = resource_id.substring(resource_id.lastIndexOf('_') + 1, resource_id.length);
var events_uri = '/get_resource_events';
$.ajax({
url: resource_base_url() + events_uri,
data: {
id: id
},
type: "GET",
dataType: 'json',
success: function(data) {
$.each(data, function(key, val){
var events = [];
var allday_data = val.allday;
if (allday_data === 'true') {
allday_data = true;
} else {
allday_data = false;
};
events.push({
id: val.id,
title: val.initials + val.last_name,
start: val.start,
end: val.end,
allDay: allday_data,
color: val.calendar_color
});
callback(events);
$('#calendar').fullCalendar('rerenderEvents');
});
}
});
}
});
});
答案 0 :(得分:0)
你试图通过json对象进行循环,尝试使用每个函数这样做。 希望它有所帮助
您必须将事件放在全局窗口范围内,如此
<script>
var events = new Array();
</script>
所有功能都在文档就绪功能中。
drop: function (start, end, timezone, callback) {
var resource_id = $(this).attr('id');
var id = resource_id.substring(resource_id.lastIndexOf('_') + 1, resource_id.length);
var events_uri = '/get_resource_events';
$.ajax({
url: resource_base_url() + events_uri,
data: {
id: id
},
type: "GET",
dataType: 'json',
success: function(data) {
$.each(data, function(key, val){
var events = [];
var allday_data = val.allday;
if (allday_data === 'true') {
allday_data = true;
} else {
allday_data = false;
};
events.push({
id: val.id,
title: val.initials + val.last_name,
start: val.start,
end: val.end,
allDay: allday_data,
color: val.calendar_color
});
callback(events);
$('#calendar').fullCalendar('rerenderEvents');
)}
}
});
}
以下是工作示例:
var events = new Array();
$(document).ready(function(){
var data = [{"id":"136","initials":"M.H.","last_name":"Tjon-Sien-Fat","start":"2014-08-05 09:00:00","end":"2014-08-05 13:00:00","allday":null,"calendar_color":"#00ffff"},{"id":"138","initials":"M.H.","last_name":"Tjon-Sien-Fat","start":"2014-08-04 09:00:00","end":"2014-08-04 13:00:00","allday":null,"calendar_color":"#00ffff"},{"id":"139","initials":"M.H.","last_name":"Tjon-Sien-Fat","start":"2014-08-07 07:30:00","end":"2014-08-07 11:30:00","allday":null,"calendar_color":"#00ffff"},{"id":"142","initials":"M.H.","last_name":"Tjon-Sien-Fat","start":"2014-08-06 00:00:00","end":"0000-00-00 00:00:00","allday":null,"calendar_color":"#00ffff"},{"id":"143","initials":"M.H.","last_name":"Tjon-Sien-Fat","start":"2014-08-06 11:30:00","end":"2014-08-06 15:30:00","allday":null,"calendar_color":"#00ffff"},{"id":"155","initials":"M.H.","last_name":"Tjon-Sien-Fat","start":"2014-08-10 09:00:00","end":"2014-08-10 13:00:00","allday":null,"calendar_color":"#00ffff"},{"id":"170","initials":"M.H.","last_name":"Tjon-Sien-Fat","start":"2014-08-28 10:00:00","end":"2014-08-28 15:00:00","allday":null,"calendar_color":"#00ffff"},{"id":"171","initials":"M.H.","last_name":"Tjon-Sien-Fat","start":"2014-08-26 08:00:00","end":"2014-08-26 12:30:00","allday":null,"calendar_color":"#00ffff"},{"id":"175","initials":"M.H.","last_name":"Tjon-Sien-Fat","start":"2014-08-30 07:00:00","end":"2014-08-30 14:30:00","allday":null,"calendar_color":"#00ffff"},{"id":"183","initials":"M.H.","last_name":"Tjon-Sien-Fat","start":"2014-08-29 07:30:00","end":"2014-08-29 13:00:00","allday":null,"calendar_color":"#00ffff"}];
$.each(data, function(key, val){
var allday_data = val.allday;
if (allday_data === 'true') {
allday_data = true;
} else {
allday_data = false;
};
events.push({
id: val.id,
title: [val.initials] + [val.last_name],
start: val.start,
end: val.end,
allDay: allday_data,
color: val.calendar_color
});
})
console.log(events);
});
这是输出
[Object, Object, Object, Object, Object, Object, Object, Object, Object, Object]
Object0: ObjectallDay: falsecolor: "#00ffff", end: "2014-08-05 13:00:00", id: "136", start: "2014-08-05 09:00:00", title: "M.H.Tjon-Sien-Fat";