I am trying to access all my data so that I can append it my html document.
I couldn't reach any of the nested arrays by using evt.locations[i].foo
because it would only return the first record.
My goal is to be able to access the variables, I have declared and append them to main_info
or secondary_info
.
Note: I will obviously be restructuring the number of paragraphs used each time but it is just to see it on the page.
$.each(data.events, function(i, evt) {
//getting all nested records
evt.locations.forEach(function(locations, i, array) {
//location data
var city = evt.locations[i].city;
var state = evt.locations[i].state;
var timeZone = evt.locations[i].timezone;
var contactPhone = evt.locations[i].contactPhone;
var contactEmail = evt.locations[i].contactEmail;
var contactName = evt.locations[i].contactName;
var address1 = evt.locations[i].address1;
var address2 = evt.locations[i].address2;
var postalCode = evt.locations[i].postalCode;
//hosts
var host = evt.locations[i].tags.host;
var specialGuest = evt.locations[i].tags.specialGuest;
var cohost = evt.locations[i].tags.cohost;
//tiers
var tierTitle = evt.locations[i].tiers[i].title;
var tierDecription = evt.locations[i].tiers[i].decription;
var tierPrice = evt.locations[i].tiers[i].price;
var tierRaiser = evt.locations[i].tiers[i].raiser;
var tierMax = evt.locations[i].tiers[i].maxNum;
var tierQuantity = evt.locations[i].tiers[i].quantity;
var shiftStart = evt.locations[i].shifts[i].startDate;
var shiftEnd = evt.locations[i].shifts[i].endDate;
//Creating variables for schema found within locations
console.log(evt.locations[i].city)
//if equal to null/nan/undefined/""
});
var main_info = '<h1>' + evt.name + '</h1>';
main_info += '<p>' + evt.templateInfo.title + '</p>';
main_info += '<p>' + evt.description + '</p>';
main_info += '<p> Date: ' + dateString + " " + timeOfEvent + '</p>';
main_info += '<button class="eventsButton">View Event Details</button>';
// only counts first record
// main_info += '<p class="mainInfo">' + evt.locations[i].city + ','
+ evt.locations[i].state +'</p>';
var secondary_info = '<h1 class="">' + 'hello' + '</h1>';
secondary_info += '<p class="">' + evt.description + '</p>';
secondary_info += '<p class="">' + evt.createdDate + '</p>';
secondary_info += '<p class="">' + evt.createdDate + '</p>';
secondary_info += '<p class="">' + evt.guestsCanInviteOthers + '</p>';