甜蜜警报 - 队列形式

时间:2018-06-13 23:39:43

标签: jquery sweetalert sweetalert2

问候我想知道是否有可能从 - 链接模式(队列)示例中获取输入数据。它只返回一个通用的值数组,是否可以获得字段名称和值之类的东西?我不知道有什么解决方案。

swal.mixin({
  input: 'text',
  confirmButtonText: 'Next →',
  showCancelButton: true,
  progressSteps: ['1', '2', '3']
}).queue([
  {
    title: 'Question 1',
    text: 'Chaining swal2 modals is easy'
  },
  'Question 2',
  'Question 3'
]).then((result) => {
  if (result.value) {
    swal({
      title: 'All done!',
      html:
        'Your answers: <pre>' +
          JSON.stringify(result) +
        '</pre>',
      confirmButtonText: 'Lovely!'
    })
  }
})

我得到的只是

Your answers:
{"value":["question 1","question 2","question 3"]}

感谢您的帮助。

Sweet Alerts 2

1 个答案:

答案 0 :(得分:1)

您可以使用preConfirm

var strAns1;
var strAns2;

swal.mixin({
  input: 'text',
  confirmButtonText: 'Next &rarr;',
  showCancelButton: true,
  progressSteps: ['1', '2', '3']
}).queue([
  {
    title: 'Question 1',
    text: 'Chaining swal2 modals is easy',
    preConfirm: function(value)
            {
                strAns1= value;
            }
  },

  {
    title: 'Question 2',
    text: 'Chaining swal2 modals is easy',
    preConfirm: function(value)
            {
                strAns2= value;
            }
  }
]).then((result) => {
  if (result.value) {
    swal({
      title: 'All done!',
      html:
        'Your answers: <pre>' +
          JSON.stringify(result) +
        '<pre>Answer1- ' + strAns1+
        '<pre>Answer2- ' + strAns2+
        '</pre>',
      confirmButtonText: 'Lovely!'
    })
  }
})
相关问题