简体   繁体   中英

How do I alert multiple results of a callback from an arrow function?

I can alert a single result from a callback but don't know how to structure my code for multiple results.

I've returned a string from my extendscript file with success but when I try to return an object or an array with multiple strings it errors

// THIS WORKS

//// extendscript.jsx
return 'success';


//// main.js
evalExtendscript(`parseProfileDCLVOD(${JSON.stringify(form)})`)
    .then(result => alert(result))  // alerts 'success'
    .catch(error => alert(error))


//---------------------------------------------------


// THIS DOESN'T WORK

//// extendscript.jsx 
var result = {
    variant: 'success',
    message: 'Export successful'
}
return result;


//// main.js
evalExtendscript(`parseProfileDCLVOD(${JSON.stringify(form)})`)
    .then(result => {
        alert(result.variant)  
        alert(result.message)  
    })
    .catch(error => alert(error))

I don't think I'm structuring my code for the result correctly.

I found the error. It was actually a problem in the extendscript.jsx. It was supposed to be:

var result = {
    variant: 'success',
    message: 'Export successful'
}
return JSON.stringify(result);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM