从didOpen sweetalert2参数传递值到.then

问题描述

我已经构建了didOpen参数,并实现了一个内部包含值的JSON对象。

问题是...如何将JSON对象传递给Swal.fire({})的随后部分。然后使用箭头功能

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
})

解决方法

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

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)
})

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...