Есть ли способ получить данные из предыдущего шага и использовать их на следующем шаге? - PullRequest
0 голосов
/ 10 января 2020

Я хочу получить значение первого шага и использовать его на втором шаге, чтобы сделать вызов ajax или выборку, и использовать данные, возвращенные во втором выборе, в конце использования трех значений в другой ajax или запрос на выборку.

Пример sweetalert2:

queue = async() => {
  const data1 = '';
  const {
    value: formValues
  } = await Swal.mixin({
    confirmButtonText: 'Next →',
    showCancelButton: true,
    progressSteps: ['1', '2', '3']
  }).queue([{
      title: 'Question 1',
      text: 'Chaining swal2 modals is easy',
      input: 'select',
      inputOptions: {
        apples: 'Apples',
        bananas: 'Bananas',
        grapes: 'Grapes',
        oranges: 'Oranges'
      },
      inputPlaceholder: 'Select a fruit',
      showCancelButton: true,
      inputValidator: (value) => {
        return new Promise((resolve) => {
          if (value != '') {
            resolve()
          } else {
            resolve('You need to select:)')
          }
        })
      }
    },
    {
      title: 'Question 2',
      text: 'Chaining swal2 modals is easy',
      input: 'select',
      inputOptions: {
        apples: 'Apples',
        bananas: 'Bananas',
        grapes: 'Grapes',
        oranges: 'Oranges'
      },
      inputPlaceholder: 'Select a fruit',
      showCancelButton: true,
      inputValidator: (value) => {
        return new Promise((resolve) => {
          if (value != '') {
            resolve()
          } else {
            resolve('You need to select:)')
          }
        })
      }
    },
    {
      title: 'Question 3',
      text: 'Chaining swal2 modals is easy',
      input: 'select',
      inputOptions: {
        apples: 'Apples',
        bananas: 'Bananas',
        grapes: 'Grapes',
        oranges: 'Oranges'
      },
      inputPlaceholder: 'Select a fruit',
      showCancelButton: true,
      inputValidator: (value) => {
        return new Promise((resolve) => {
          if (value != '') {
            resolve()
          } else {
            resolve('You need to select:)')
          }
        })
      }
    }
  ]).then((result) => {
    if (result.value) {
      const answers = JSON.stringify(result.value)
      Swal.fire({
        title: 'All done!',
        html: `
            Your answers:
            <pre><code>${answers}
`, подтвердитеButtonText: 'Прекрасно!' })}})}
<script src="https://cdn.jsdelivr.net/npm/sweetalert2@9"></script>

<h1>sweetalert2 queue!</h1>
<button type="button" class="btn btn-info" onclick="queue();">Info</button>

Я нашел что-то похожее, но в этой ссылке не очень понятно

...