javascript - 将 didOpen sweetalert2 参数中的值传递给 .then
问题描述
我已经构建并实现了一个带有值的 JSON 对象的 didOpen 参数。
问题是......如何将该 JSON 对象传递给 Swal.fire({ }) .then 箭头函数的 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
})
解决方案
解决方案是在 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)
})
推荐阅读
- android - Android @SuppressWarnings 在语句级别,而不是方法级别
- angular - 离子日期时间绑定到纪元
- ios - 从 iPhone 触发 Apple Watch 应用程序启动
- android - 使用带有 POP3 或 IMAPS 协议的 javamail 检索所有 uread 电子邮件
- openstack - 如何使用 svirt 保护虚拟机管理程序?
- javascript - 如何使表单具有响应性
- symfony - Symfony 4 - 分组类别
- sccm - SCCM 设备未显示在设备集合中
- c# - 何时在 windows 窗体 .net 应用程序中加载 pre-jit 编译?
- radio-button - 获取选择单选按钮时显示的所选数据[离子]