0👍
After some tries and after reading some questions on how to implement an async call inside a loop, I’ve opted to use the Array.prototype.map
function and it’s working fine. I’ve modified my vue method that is calling the library to an async method, but I leave untuched the then
block so I will be able to get the processed documents after the library finished processing them.
this.dataPlaceholders.map( async (data, i) => {
let filename = data.supplier + '.docx'
this.docxTemplate.process(template, data).then( (result) => {
// code to download files here
let a = document.createElement('a')
let downloadLink = URL.createObjectURL(result)
a.href = downloadLink
a.download = filename
a.click()
})
})
The only thing to solve is how I can revoke the blob url after all files are downloaded.
- [Vuejs]-Error: The requested module 'vue' does not provide an export named 'default'
- [Vuejs]-Github pages isn't loading my Vue project assets
0👍
My suggestion is to use a for loop instead of the map
function, if your function is async you can try using this code
async function myFunc(){
for( let i = 0; i < myArray.length; i++ ){
await functionTocall(param1, param2)
}
}
The for loop will wait until the async function return a promise, in this way you will be sure that the function inside the loop will be executed correctly.
Source:stackexchange.com