I am currently facing an issue with a chained AXIOS call that is triggered from an array. The challenge I am encountering is ensuring that the second call completes before the first one initiates another API request, which seems to be working fine so far. However, my main problem lies in the fact that I am unable to reference anything from within the response of the second chain. I need to update either the calling array (arr), a public array this.excelData.results, or even a deep copy of the original array. Each time I try to access the data, I receive the following error message:
TypeError: Cannot read property 'ORCID' of undefined at eval (webpack-
internal:///./node_modules/cache-loader/dist/cjs.js?!./node_modules/babel-
loader/lib/index.js!./node_modules/cache-loader/dist/cjs.js?!./node_modules/vue-
loader/lib/index.js?!./src/views/examples/ExcelWorksheet.vue?vue&type=script&lang=js&:410:49) at
NodeList.forEach (<anonymous>) at eval (webpack-internal:///./node_modules/cache-
loader/dist/cjs.js?!./node_modules/babel-loader/lib/index.js!./node_modules/cache-
loader/dist/cjs.js?!./node_modules/vue-loader/lib/index.js?!./src/views/examples/ExcelWorksheet.vue?
vue&type=script&lang=js&:381:28) at NodeList.forEach (<anonymous>) at eval (webpack-
internal:///./node_modules/cache-loader/dist/cjs.js?!./node_modules/babel-
loader/lib/index.js!./node_modules/cache-loader/dist/cjs.js?!./node_modules/vue-
loader/lib/index.js?!./src/views/examples/ExcelWorksheet.vue?vue&type=script&lang=js&:378:33)
I have attempted using 'this' and 'self', but nothing appears to resolve the issue. While debugging in a browser, all elements of the array are visible, yet I am unable to retrieve or manipulate them in code. Is there a specific procedure I should follow to access the data from the second AXIOS call within the original array?
lookUpORCID(){
this.pubmedArticles=[];
this.makeRequestsFromArray(this.excelData.results);
},
makeRequestsFromArray(arr) {
var self = this
let index = 0;
function request() {
let authorName = arr[index]["Last_Name"]
let linkGetIdList = 'https://eutils.ncbi.nlm.nih.gov/entrez/eutils/esearch.fcgi?';
linkGetIdList += 'tool=biosketch&db=pubmed&retmode=json&retmax=200&';
linkGetIdList += 'term=' + authorName +'[AU] ';
return axios.get(linkGetIdList).then((res) => {
index++;
let idlist = res.data.esearchresult.idlist
const passID = idlist.join(',')
if (idlist.length > 0) {
var getXmlLink = 'https://eutils.ncbi.nlm.nih.gov/entrez/eutils/efetch.fcgi?';
getXmlLink += 'db=pubmed&retmode=xml&id=${passID}';
return axios.get(getXmlLink).then((response) => {
// parse document
const parser = new DOMParser()
const xmlDoc = parser.parseFromString(response.data, 'text/xml') // Get ALL XML content
// Do Stuff
**This is the spot that I need to change value in array**
let xyz = arr[index]["ORCID"]
return request();
})
}
if (index >= arr.length) {
return 'done'
}
});
}
return request();
}
}