ForEach fejl - Problem med at gennemløb af JSON
$(document).ready(() => {SDK.Student.loadNavbar();
const $EventList = $("#event-list");
SDK.Event.getEvents((err, Event) => {
console.log(Event);
Event.forEach((event) => {
const eventHtml = ` <!--Tegnet her gør, at man bare kan skrive det som almindelig tekst, og ikke skrive " + + ". -->
<div class="col-lg-4 book-container">
<div class="panel panel-default">
<div class="panel-heading">
<h3 class="panel-title">${event.eventName}</h3>
</div>
<div class="panel-body">
<div class="col-lg-4">
<img src="${event.imgUrl}"/>
</div>
<div class="col-lg-8">
<dl>
<dt>Description</dt>
<dd>${event.description}</dd>
<dt>Owner</dt>
<dd>${event.owner}</dd>
<dt>Date</dt>
<dd>${event.eventDate}</dd>
<dt>Location</dt>
<dd>${event.location}</dd>
</dl>
</div>
</div>
<div class="panel-footer">
<div class="row">
<div class="col-lg-4 price-label">
<p>Kr. <span class="price-amount">${event.price}</span></p>
</div>
<div class="col-lg-8 text-right">
<button class="btn btn-success purchase-button" data-book-id="${event.id}">Add to attending events</button>
</div>
</div>
</div>
</div>
</div>`;
$EventList.append(eventHtml);
});
Event indeholder dette:
[{"idEvent":12,"price":50,"owner":23,"eventName":"abekatten","location":"CBS","eventDate":"dette er en dato","description":"dette er en beskrivelse"},{"idEvent":14,"price":10,"owner":25,"eventName":"testevent","location":"Kilentest","eventDate":"testdato123","description":"testdescription123"},{"idEvent":16,"price":999,"owner":25,"eventName":"HejAlbert","location":"SBC","eventDate":"123nu","description":"dette er nu opdateret"},{"idEvent":17,"price":2004,"owner":25,"eventName":"kryp","location":"kryps","eventDate":"dato","description":"kryptest"}]