jquery - Bootstrap modal 不会在 adminlte 中更新内容和重置表单
问题描述
当我打开带有数据的模式并关闭它并再次打开时,表单不会重置并显示旧数据我该如何修复它并初始化表单数据?
我使用 bootstrap v3.3.7 和 adminlte v2
模态html:
<div class="modal fade" id="new" tabindex="-1" aria-hidden="true">
<div class="modal-dialog modal-lg">
<div class="modal-content">
<div class="modal-body">
<img src="/image/loading.gif" class="loading"/>
<span>Lodaing . . .</span>
</div>
</div>
</div>
</div>
点击按钮:
<button href="/edit/id" data-target="#new" data-toggle="modal" type="button" class="btn btn-success">Edit</button>
使用spring boot控制器打开模态内容:
@RequestMapping(value = "/edit")
public String edit(Model model,
@ModelAttribute(value = "id") String paramId){
if (paramId == 0){
//open modal without data...
}
if (paramId != 0){
//open modal with data...
}
model.addAttribute("edit", data);
return "view/edit"; //open modal html template
}
解决方案
将其放入页面的 javascript 中,以在关闭时清除模式内容:
$(document).on('hidden.bs.modal', '.modal', function (e) {
// Handles the event thrown when a modal is hidden
$(this).removeData('bs.modal');
$(this).find(".modal-content").empty();
});
推荐阅读
- monitoring - Zabbix 立即触发警报,而不是根据 sec 输入值
- reactjs - 简单的 React+Redux 应用程序会导致“警告:传递给 useMemo 的最终参数在渲染之间改变了大小。” 对于每个状态变化
- c# - 如何在 MVC 控制器中获取当前的 url 协议?
- c++ - 我不确定这段代码的行为。有人可以向我解释吗?
- r - 如何通过从两个不同的列中获取 x 轴值来绘制?
- c# - UWP 和 BitmapDecoder 问题 - 感觉像是线程问题
- python - concurrent.futures 库中 ProcessPoolExecutor 中的奇怪行为
- python-3.x - 这个继承的我的python tkinter网格在哪里?
- regex - 用正则表达式替换url中的字符
- c# - 当前上下文 C# 中不存在名称 VARname