I am building a job list, But.. the client wants me
to group jobs by 'location' - so I collected the items
into groups by location (i might have in a badly formatted way)
and trying to append them back for cant get the forEach to work.
alljobs = [];
counter = 1;
departments = {};
var apiurl = "https://www.comeet.co/careers-api/2.0/company/UID_KEY_HERE/positions/?token=TOKEN_KEY_HERE&details=true";
fetch(apiurl)
.then(res => res.json())
.then((out) => {
$.each(out, function() {
// console.log(this);
if(this.department && this.location.name) {
!(this.location.name in alljobs) ? alljobs[this.location.name] = [] : '';
alljobs[this.location.name][counter] =
'<div class="job-item '+this.uid+' '+string_to_slug(this.department)+'">'
+'<div class="row" data-jobid="'+this.uid+'">'
+'<div class="col-md-4 item-title"><a href="<?php echo get_permalink($comeet['positions_page']); ?>?jobid='+this.uid+'">'+ this.name +'</a></div>'
+'<div class="col-md-2 expertise">'+ this.location.name +'</div>'
+'<div class="col-md-3 expertise">'+ this.department +'</div>'
+'<div class="col-md-3 job-link"> <a href="<?php echo get_permalink($comeet['positions_page']); ?>?jobid='+this.uid+'" class="btn btn-info gotoPosition" data-jobid="'+this.uid+'"><?php _e("Details", THEME_NAME); ?></a> </div>'
+'</div>'
+'</div>';
departments[this.department] = '<li class="jobsPicker" data-show="'+string_to_slug(this.department)+'">'+this.department+'</li>';
counter++;
}
});
})
.catch(err => { throw err });
/********************************************************
** APPEND ALL JOBS
********************************************************/
if(alljobs) {
console.log(alljobs.length); // RETURNS 0 <--- WHY?!
console.log(alljobs);
alljobs.forEach(function(params) { // DOESNT RUN
console.log(params);
})
}