I have a function where I want to finish the first this.findLocation()
on every loop before returning the jsonObject. The problem is when the function returns the jsonObject, some of the findlocation
still not finished loop.
This is the code for the function:
generate (item) {
let jsonObj = {}
jsonObj.lookup = this.id
this.fields.forEach(field => {
if (field.prop === 'API') {
this.findLocation(item, field).then(function (value) {
let location = value
if (location) jsonObj[field.prop] = location.id
})
} else {
jsonObj[field.prop] = item[field.header]
}
})
return jsonObj
}
Any help would be appreciate.