I'm calling this.getAllJobsAPI(); in the render function.
This successfully calls the getAllJobsAPI (as given below) and I'm able to retrieve job name from the JSON array of jobs.
getAllJobsAPI(){
var headers = new Headers();
headers.append('Authorization', 'Basic YWRtaW46YWRtaW4=');
fetch('http://localhost:8080/api/json', {headers: headers})
.then((result) => {
// Get the result
// If we want text, call result.text()
return result.json();
}).then((jsonResult) => {
// get all jobs
var jobs = [];
Object.keys(jsonResult.jobs).forEach(function(key) {
jobs.push(jsonResult.jobs[key].name);
var job = jsonResult.jobs[key].name;
console.log(job);
this.getLastBuildAPI(job);
});
//var a = 'meetup';
//this.getLastBuildAPI(a);
console.log(jsonResult);
})
}
But calling this.getLastBuildAPI(job); within the for each loop throws "Uncaught (in promise) TypeError: Cannot read property 'getLastBuildAPI' of undefined" error. But If I hardcode a name variable in the end of the function and call this.getLastBuildAPI(a); I could get the success response.
Could someone tell me why I'm not able to call this.getLastBuildAPI(job); within for-each of the JSON array? Note that I'm able to see job variable in console.
Thanks,