我试图在 $.each()
循环中显示模态对话框,并且在每次迭代中我都会动态更改模态的数据。
$.each(real_names, function (key, value) {
$('#restore-modal').find('.asset_name').text(value.relative_name);
$('#restore-modal').modal('open');
}
问题是 $.each()
没有等待用户与模式交互或模式关闭。
如何等待用户与模式交互或模式关闭?
最佳答案
我不知道你使用的模态库的API是什么,但你可能可以尝试使用递归函数,它的计数器,它允许你循环 real_names
数组,同时让您完全控制循环:
var counter = 0;
function openModal() {
// first a mecanism to escape the recursion:
if (counter === real_names.length) {
return;
}
// not sure about your code here, but for the idea:
$('#restore-modal').find('.asset_name').text(real_names[counter].relative_name);
$('#restore-modal').modal('open');
// here, depending on how your modal API works, you can call again
// the openModal function after the desired event (user closing modal,
// clicking on confirmation...),
// first incrementing the counter for searching the next modal
// or make the function return, to escape the recursion for any other event
}
关于javascript - Jquery 每个等待模态关闭,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50157106/