javascript - Jquery 每个等待模式关闭
问题描述
我试图在$.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 - 在 Javascript 中不间断地切换
- amazon-dynamodb - dynamodb 过滤不在列表中的值
- firebase - 如果文档 ID 等于当前用户,如何查询 Firestore 以返回字符串
- spring-boot - 我已经用 openapi-generator-maven-plugin 生成了我的 API 服务器,现在怎么办?
- composer-php - 如何从“pre-package-update”监听器取消作曲家更新操作
- wpf - WPF 对齐菜单项
- angular - 从 clr-dropdown 获取值
- javascript - 旋转圆柱体(硬币)的等距计算
- reactjs - 尝试在不让用户单击按钮的情况下自动运行方法
- java - 如何点击网页元素来显示日期选择器?