SweetAlert dropdown dynamically add items in list

前端 未结 1 965
青春惊慌失措
青春惊慌失措 2021-01-19 09:58

I am currently using sweetalert2 to capture user\'s input from the dialog. I would like to use the dropdown in chaining queue dialog but I can\'t seem to find a way to dynam

1条回答
  •  离开以前
    2021-01-19 10:54

    As the SweetAlert2 documentation says, inputOptions parameter can be object or Promise.

    To populate select items dynamically you should use promises, here's the simple example:

    var inputOptionsPromise = new Promise(function (resolve) {
      // get your data and pass it to resolve()
      setTimeout(function () {
        resolve({
          '#FF0000': 'Red',
          '#00FF00': 'Green',
          '#0000FF': 'Blue'
        })
      }, 2000)
    })
    
    Swal.fire({
      input: 'select',
      inputOptions: inputOptionsPromise
    })

    Notice, that SweetAlert2 will automatically show a loader until the Promise for inputOptions parameter will be resolved or rejected.

    0 讨论(0)
提交回复
热议问题