1
현재 대화 상자에서 사용자의 입력을 캡처하는 데 sweetalert2를 사용하고 있습니다. 연결 대기열 대화 상자에서 드롭 다운을 사용하고 싶지만 드롭 다운 목록에 항목을 동적으로 추가하는 방법을 찾지 못하는 것 같습니다. JSON 형식에서 데이터를 검색하여 드롭 다운 목록에 넣으려는 경우이를 수행 할 수있는 방법이 있습니까?SweetAlert 드롭 다운 목록에 항목을 동적으로 추가하십시오.
function userInput() {
swal.setDefaults(
{
showLoaderOnConfirm: true,
confirmButtonText: 'Next →',
showCancelButton: true,
animation: true,
progressSteps: ['1', '2', '3']
}
);
var steps = [
{
text: 'Select an author to analyze the commit',
input: 'select',
inputOptions: {
'SRB': 'Serbia', // How do I dynamically set value?
'UKR': 'Ukraine',
'HRV': 'Croatia'
}
},
{
text: 'Select multiple authors to compare their commits',
input: 'select',
inputOptions: {
'SRB': 'Serbia', // How do I dynamically set value?
'UKR': 'Ukraine',
'HRV': 'Croatia'
}
},
{
text: 'Select a file directory to analyze all author\'s commit',
input: 'select',
inputOptions: {
'SRB': 'Serbia', // How do I dynamically set value?
'UKR': 'Ukraine',
'HRV': 'Croatia'
}
}
];
swal.queue(steps).then(function(result) {
swal.resetDefaults();
swal({
type: 'success',
title: 'Success',
text: 'Scroll down for statistics!',
html:
'Your selections: <pre>' +
JSON.stringify(result) +
'</pre>',
confirmButtonText: 'Ok',
showCancelButton: false
})
}, function() {
swal.resetDefaults()
})
}
는 JSON 형식으로 데이터를 검색하십시오 SweetAlert2 documentation 말한다
function getData(repolink) {
readDataFromGit('https://api.github.com/repos/' + repolink + '/git/trees/master?recursive=1', function(text){
data = JSON.parse(text);
$.each(data, function(i, v) {
// Retrieve v.login data!
data = v.login;
})
});
}
function readDataFromGit(link, callback) {
var request = new XMLHttpRequest();
request.overrideMimeType("application/json");
request.open('GET', link, true);
request.onreadystatechange = function() {
if (request.readyState === 4 && request.status == "200") {
callback(request.responseText);
}
};
request.send(null);
}