You're using $.map
incorrectly. The point of it is that it creates an Array, so there's no need to create one before the loop and .push()
into it.
You should keep the return
statement, remove the .push
, and set the return value of $.map
to the events
variable.
success: function (response) {
var events = $.map(response.d, function (item) {
var event = new Object();
event.id = item.EventID;
event.start = new Date(item.StartDate);
event.end = new Date(item.EndDate);
event.title = item.EventName;
return event;
});
callback(events);
},
However, object literal syntax is nicer.
success: function (response) {
var events = $.map(response.d, function (item) {
return {
id: item.EventID,
start: new Date(item.StartDate),
end: new Date(item.EndDate),
title: item.EventName,
};
});
callback(events);
},
The error message shown in your question doesn't seem to make sense for the code provided.