I have a HTML table that’s displaying all of my database’s data (individual job listings). However, I need to write an if statement to only show a job if the job’s createdByUserID matches the ID of the user viewing it.
$(function() {
var records = [];
$.getJSON('https://db-ommitted-for-privacy?tableName=JobListings&fields=company,logo,img,companyDescription,role,roleDescription,location,link,createdByUserID,dateAdded&view=AllListings', function(data) {
$.each(data.records, function parseJSON(i, { fields: f }) {
var tblRow = "<tr>" +
"<td>" +
"<div style='padding-top: 1%; padding-bottom: 1%;'>" +
"<div style='border: 1px solid black;'>" +
"<button class='accordionList' style='font-size: large; outline: none;'>" +
"<span style='padding-top: 2.5%; padding-bottom: 3%;'>" +
"<img src='" + f.logo + "' height='30px'>" +
"</span> <span style='padding-top: 3%; padding-bottom: 3%;'> " +
f.company + " | " + f.role +
" <span style='color: #2b2b2b;''><span class='iconify-inline' data-icon='eva:pin-outline' style='color: #2b2b2b;'></span> " + f.location +"</span></span>" +
"</button>" +
"<div class='panel'>" +
"<img src='img/jobBanner2.png' width='100%'>" +
"<br>" +
"<p style='color: #505050;'>Posted: " + f.dateCreated + " | Status: " + f.status + "</p>" +
"<h4>About this role:</h4>" +
"<p>" + f.roleDescription + "</p>" +
"<h4>About " + f.company + ":</h4>" +
"<p>" + f.companyDescription + "</p>" + "<br>" +
"<a href='pricing.html' class='button btn btn-lg btn-block btn-sm button-black' style='padding-top: 1%; padding-bottom: 1%; width: 200px;'>Apply <span class='iconify-inline' data-icon='bi:arrow-right-circle' data-width='15' style='color: white;'></span></a>" +
"<br>" + "</div>" +
"</div>" +
"</div>" +
"</div>" +
"</td>" +
"</tr>"
$(tblRow).appendTo("#userdata tbody");
});
});
});
The code to display a logged in user’s ID:
<div data-ms-member="id"></div>
I understand the concept of how this should work, but I have no idea how to execute it in JS and HTML. Any help is appreciated, thanks.