Javascript 将一个值从didOpen sweetalert2参数传递到。然后

Javascript 将一个值从didOpen sweetalert2参数传递到。然后,javascript,sweetalert2,Javascript,Sweetalert2,我已经构建了didOpen参数并实现了一个JSON对象,其中包含值 问题是。。。如何将该JSON对象传递给Swal.fire({}).then-arrow函数的then部分 Swal.fire({ html: ` HERE IS ALL THE ID's STUFF `, didOpen() { let itemPOST = { /* the json i trying to catch */ } // do bunch of stuff and save

我已经构建了didOpen参数并实现了一个JSON对象,其中包含值

问题是。。。如何将该JSON对象传递给Swal.fire({}).then-arrow函数的then部分

Swal.fire({
  html: ` HERE IS ALL THE ID's STUFF `,
  didOpen() {
    let itemPOST = {
      /* the json i trying to catch */ }

    // do bunch of stuff and save it into itemPOST

  } //==>end of didOpen
}).then(() => {
  //console log here for itemPOST
})
let giveMeTheValue;  //<==    variable to receive the value
Swal.fire({
  html: ` HERE IS ALL THE ID's STUFF `,
  didOpen() {
    let itemPOST = { /* the json with data */ }

    // do bunch of stuff and save it into itemPOST

    giveMeTheValue = itemPOST   //<== giving the data to pass to then()
  } 
}).then(() => {
  console.log(giveMeTheValue)
})

解决方案是在swal之后包含一些变量,将值传递给该变量,并在.then()箭头函数中调用它

Swal.fire({
  html: ` HERE IS ALL THE ID's STUFF `,
  didOpen() {
    let itemPOST = {
      /* the json i trying to catch */ }

    // do bunch of stuff and save it into itemPOST

  } //==>end of didOpen
}).then(() => {
  //console log here for itemPOST
})
let giveMeTheValue;  //<==    variable to receive the value
Swal.fire({
  html: ` HERE IS ALL THE ID's STUFF `,
  didOpen() {
    let itemPOST = { /* the json with data */ }

    // do bunch of stuff and save it into itemPOST

    giveMeTheValue = itemPOST   //<== giving the data to pass to then()
  } 
}).then(() => {
  console.log(giveMeTheValue)
})
让给定methevalue//