Skip to content

Instantly share code, notes, and snippets.

@alduro
Created July 3, 2011 15:22
Show Gist options
  • Save alduro/1062309 to your computer and use it in GitHub Desktop.
Save alduro/1062309 to your computer and use it in GitHub Desktop.
$.ajax({
url: '/ajax_nyc_events',
dataType: 'json',
success: function(doc) {
$.each(doc, function( index, value ) {
var eventDate = new Date(value.start);
var keyDateFormat = $.fullCalendar.formatDate(eventDate, 'dd MMM yyyy');
if (eventsByDayNYC[keyDateFormat] === undefined) { // date doesn't exist as key
//Create events array and add it
var temp_events = [];
temp_events.push(value);
eventsByDayNYC[keyDateFormat] = temp_events;
} else {
//Just add to events array
eventsByDayNYC[keyDateFormat].push(value);
}
});
var eventsToShowInCalendar = [];
for (var index in eventsByDayNYC) {
eventsToShowInCalendar.push({ title: eventsByDayNYC[index].length + ' events', start: index , allDay: true});
}
callback(eventsToShowInCalendar);
}
});
JSON data:
[{"start": "2011-07-03", "event_url": "http://www.nycgovparks.org/events/2011/07/03/summer-on-the-hudson-downtown-boathouse-kayaking-on-the-hudson", "name": "Summer on the Hudson: Downtown Boathouse Kayaking on the Hudson"}, {"start": "2011-07-04", "event_url": "http://www.nycgovparks.org/events/2011/07/04/introductions-to-qigong", "name": "Introductions to Qigong"}, {"start": "2011-07-04", "event_url": "http://www.nycgovparks.org/events/2011/07/04/the-july-4th-marathon", "name": "The July 4th Marathon"}, {"start": "2011-07-04", "event_url": "http://www.nycgovparks.org/events/2011/07/04/sunset-qi-gong-classes", "name": "Sunset Qigong Classes"}, {"start": "2011-07-05", "event_url": "http://www.nycgovparks.org/events/2011/07/05/weekday-fitness-walking-program1", "name": "Weekday Fitness Walking Program"}, {"start": "2011-07-05", "event_url": "http://www.nycgovparks.org/events/2011/07/05/bryant-park-tai-chi", "name": "Bryant Park Tai Chi"}, {"start": "2011-07-05", "event_url": "http://www.nycgovparks.org/events/2011/07/05/fit-walk-step-out", "name": "Free Fitness Walk (Step Out)"}, {"start": "2011-07-05", "event_url": "http://www.nycgovparks.org/events/2011/07/05/learn-to-play-tennis-ages-5-to-161", "name": "Learn to Play Tennis: Ages 5 to 16"}, {"start": "2011-07-05", "event_url": "http://www.nycgovparks.org/events/2011/07/05/bryant-park-yoga", "name": "Bryant Park Yoga"}, {"start": "2011-07-05", "event_url": "http://www.nycgovparks.org/events/2011/07/05/summer-on-the-hudson-presents-mat-pilates", "name": "Summer on the Hudson presents Mat Pilates"}, {"start": "2011-07-05", "event_url": "http://www.nycgovparks.org/events/2011/07/05/yoga-in-the-park", "name": "Yoga in the Park"}, {"start": "2011-07-05", "event_url": "http://www.nycgovparks.org/events/2011/07/05/pilates-with-the-fitness-guru-in-brooklyn-bridge-park", "name": "Pilates with the Fitness Guru in Brooklyn Bridge Park"}, {"start": "2011-07-06", "event_url": "http://www.nycgovparks.org/events/2011/07/06/summer-on-the-hudson-tots-soccer-and-pee-wee-basketball", "name": "Summer on the Hudson: Tots Soccer and Pee Wee Basketball"}]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment