涉及主页面内嵌iframe中的列表数据的保存

场景:主表 : 附表 = 1 : m,同一个页面,共同使用一个保存按钮进行两个表的数据保存,页面中间有个查询按钮,可以对子iframe页面的内容进行刷新

流程项目页面内嵌了个子iframe,项目页面表单数据提交保存是一个主表(loan_item_apply),内嵌iframe中的列表数据需要存储于附表中(loan_item_apply_funding)

方案:点击保存时,获取子iframe,将子iframe中需要保存的数据以隐藏域的方式拼接到父窗口的form下方,由于子iframe中的数据是列表数据,所以需要在loan_item_apply表对应的映射类里面添加loan_item_apply_funding表的映射类列表属性

LoanItemAppply类

java 复制代码
private List<LoanItemApplyFunding> fundingList;

获取子iframe中form表单的属性和值并拼接隐藏域于父窗口的form下方

javascript 复制代码
// 调用子iframe中的方法,校验资金方是否使用完成
var iframeWindow = document.getElementById("fundingIframe").contentWindow;
var isFinishUseMoney = iframeWindow.checkFundingMoney(); // 在父窗口中调用子iframe内的function
 if (!isFinishUseMoney){
     return;
 }else{ // 在form表单中拼接项目-资金方存表的相关信息
     const form = document.getElementById("loanItemApplyForm"); // 父窗口表单form
     const table = iframeWindow.document.getElementById("loanItemApplyFundingListDetail"); // 子iframe里的form里面的列表属性
     const rows = table.querySelectorAll("tr");
     for (let i = 1; i < rows.length; i++) { // 获取第二个tr及后续的tr
         const row = rows[i];
         // 检查复选框选中的row
         const checkbox = row.querySelector("input[type='checkbox']");
         if (null != checkbox){
             if (checkbox.checked) { // 遍历选中已勾选的tr
                 // 获取所有input标签内容并新增input隐藏域拼接在form表单后面
                 const inputs = row.querySelectorAll("input");
                 inputs.forEach((input) => {
                     const hiddenInput = document.createElement("input");
                     hiddenInput.type = "hidden";
                     hiddenInput.name = input.name;
                     hiddenInput.value = input.value;
                     form.appendChild(hiddenInput);
                 });
                 // 获取所有select标签内容并新增input隐藏域拼接在form表单后面
                 const selects = row.querySelectorAll("select");
                 selects.forEach((select) => {
                     const hiddenInput = document.createElement("input");
                     hiddenInput.type = "hidden";
                     hiddenInput.name = select.name;
                     hiddenInput.value = select.value;
                     form.appendChild(hiddenInput);
                 });
             }
         }
     }
 }

子iframe中form里面的列表属性展示

html 复制代码
<!-- foreach循环遍历后端传过来的list -->
<tr>
	<!-- input框 -->
	<td>
		<input type="checkbox" class="pk" name="fundingList[${item.index}].属性名"
			   id="fundingList[${item.index}].属性名" 
			   value="${fundingList元素中对应的属性值}" />
	</td>
	<!-- select下拉框 -->
	<td>
		<select id="fundingList[${item.index}].属性名" name="fundingList[${item.index}].属性名" value="${fundingList元素中对应的属性值}">
			<!-- 循环遍历下拉框选项optionList -->
			<option value="${optionList元素中对应的属性值}">${optionList元素中对应的属性值}</option>
		</select>
	</td>
</tr>
相关推荐
Mr.Jessy14 小时前
JavaScript高级:构造函数与原型
开发语言·前端·javascript·学习·ecmascript
白兰地空瓶16 小时前
🚀你以为你在写 React?其实你在“搭一套前端操作系统”
前端·react.js
爱上妖精的尾巴16 小时前
6-4 WPS JS宏 不重复随机取值应用
开发语言·前端·javascript
Goldn.17 小时前
Java核心技术栈全景解析:从Web开发到AI融合
java· spring boot· 微服务· ai· jvm· maven· hibernate
似水流年QC17 小时前
深入探索 WebHID:Web 标准下的硬件交互实现
前端·交互·webhid
陪我去看海17 小时前
测试 mcp
前端
speedoooo17 小时前
在现有App里嵌入一个AI协作者
前端·ui·小程序·前端框架·web app
全栈胖叔叔-瓜州18 小时前
关于llamasharp 大模型多轮对话,模型对话无法终止,或者输出角色标识User:,或者System等角色标识问题。
前端·人工智能
李慕婉学姐18 小时前
【开题答辩过程】以《基于Android的出租车运行监测系统设计与实现》为例,不知道这个选题怎么做的,不知道这个选题怎么开题答辩的可以进来看看
java·后端·vue
三七吃山漆18 小时前
攻防世界——wife_wife
前端·javascript·web安全·网络安全·ctf