I am using Date.js to display some dates and a weird thing happens. If I use it in an array formed from within an each statement.
Here is what i mean:
If I pass and use the events_array to the test function array everything works fine, but if I use the eventsArray one, that should look the same, I get:
startDate is undefined
...new Date(startDate.getFullYear(), startDate.getMonth(), startDate.getDate()).getTime()...
function getTest() {
$.ajax({
type: "GET",
url: "/index",
dataType: "json",
success: function (data) {
var eventsArray = new Array();
jQuery.each(data, function (i, val) {
eventsArray.push(
new Array({
startDate: new Date(2011, 07, 20, 15, 50),
endDate: new Date(2012, 00, 10),
}));
});
var events_array = new Array({
startDate: new Date(2011, 07, 20, 15, 50),
endDate: new Date(2012, 00, 10),
}, {
startDate: new Date(2011, 07, 20, 15, 50),
endDate: new Date(2012, 00, 10),
});
test(events_array);
}
});
}
Any ideas?
Thanks
You probably meant to fill
eventArraywith objects, not arrays with a single object in each one: