I have this method :
callHttp( isRefreshed ) {
// Prepare the data
let importData = {
token: this.mappingData.token,
xml_file_url: this.mappingData.xml_file_url,
name: this.mappingData.mapping_name,
encoding: this.mappingData.encoding,
auth_info: this.mappingData.auth,
category_delimitor : this.mappingData.category_delimitor,
};
// Show the loading
this.loadDone = true;
// Get the mapping fields
http.post("projects/import", importData)
.then((response) => {
let res = response.data;
if (res.status !== "ready") {
setTimeout(()=>{
//_this.mappingData.projectFieldOptions = [];
this.callHttp( isRefreshed );
this.loadDone = true;
}, 5000);
} else if (res.status === "ready") {
// if no fields name found
this.countHTTP == 0;
if (res.field_names === false) {
this.loadDone = false;
this.hasMappingError = true;
} else {
this.loadDone = false;
this.isRefreshing = false;
this.hasMappingError = false;
this.mappingData.id_feed = res.id_feed;
this.id_mapping_processing = res.id_mapping_processing;
this.projectToken = res.id_project;
if( isRefreshed ) {
//_this.mappingData.newProjectFieldOptions = [];
res.field_names.forEach(function (item, index) {
this.mappingData.newProjectFieldOptions.push({
value: item,
text: "Do Not Import",
custom: null,
});
});
// Combined the old mapping data with the new one and remove duplicate key/value
const filteredProjectFieldOptions = [...new Map([...this.mappingData.newProjectFieldOptions, ...this.mappingData.projectFieldOptions]
.map((item) => [item.value, item])).values()];
this.mappingData.projectFieldOptions = [];
this.mappingData.projectFieldOptions = filteredProjectFieldOptions;
} else {
//_this.mappingData.projectFieldOptions = [];
res.field_names.forEach(function (item, index) {
this.mappingData.projectFieldOptions.push({
value: item,
text: "Do Not Import",
custom: null,
});
});
}
}
}
})
.catch((error) => {
console.log(error);
});
},
Now, after this } else if (res.status === "ready") {
statement I get an error on the console log :
TypeError: this is undefined
Can you tell me how can I fix it?
I can use let _this = this
but I don't want to use this.