系列文章目录
前言
本系列文章主要记录项目过程中重点的项目技术
一、目标
B对象选择器弹窗的值需要根据A的值进行筛选,所以A的值必须作为参数传递给B
二、实现目标
1.实现步骤
1.创建一个函数在B对象选择器点击但是弹窗弹出之前调用,并通过这个函数获得A的值,并作为一个参数传给B的链接
<div class="col-xs-6">
<div class="form-group">
<label class="control-label col-sm-4" title="">
<span class="required hide">*</span> ${text('隧道选择')}:<i class="fa icon-question hide"></i></label>
<div class="col-sm-8">
<#form:listselect id="tunnel" title="隧道选择" path="tunnelId" labelPath="tunnel.name"
url="${ctx}/lbst/subsectionStation/tunnelSelect" allowClear="true" checkbox="false" itemCode="id"
itemName="name" callbackFuncName="callMsg()" getSelectDataFuncName="changeData()" class="required " />
<#form:hidden path="tempId"/>
</div>
</div>
</div>
<div class="col-xs-6">
<div class="form-group">
<label class="control-label col-sm-4" title="">
<span class="required hide">*</span> ${text('隧道分段选择')}:<i class="fa icon-question hide"></i></label>
<div class="col-sm-8">
<#form:listselect id="subsection" title="隧道分段选择" path="subsectionId" labelPath="subsection.subsectionCode"
url="${ctx}/lbst/subsectionStation/subsectionSelect" allowClear="true" checkbox="false" itemCode="id"
itemName="subsectionCode" getSelectDataFuncName="updateSusectionURL()"
class="required " />
</div>
</div>
</div>
//通过窗口弹出前的方法获得id参数
var updateSusectionURL = function(){
var cc = $("#tunnelCode").val();
if(cc==""){
js.showMessage("请先选择隧道,然后在选择分段");
$("#subsectionDiv").attr("data-url","${ctx}");
return null;
}else{
$("#subsectionDiv").attr("data-url","${ctx}/lbst/subsectionStation/subsectionSelect?id="+cc);
}
}
2.在后台将得到的参数作为一个属性传给页面
后台JAVA代码如下:
@RequiresPermissions("lbst:subsectionStation:view")
@RequestMapping(value = "subsectionSelect")
public String subsectionSelect(Subsection subsection, String selectData, Model model,String id) {
String selectDataJson = EncodeUtils.decodeUrl(selectData);
Tunnel tunnel = new Tunnel();
//将接口的参数id设置为tunnel的属性id的值
tunnel.setId(id);
subsection.setTunnelCode(tunnel);
if (JsonMapper.fromJson(selectDataJson, Map.class) != null) {
model.addAttribute("selectData", selectDataJson);
}
model.addAttribute("subsection", subsection);
return "modules/lbst/subsectionSelect";
}
3.在subsectionSelect页面添加筛选属性,如下图
<#form:hidden path="tunnelCode.id" />
4.select页面的Java接口
/**
* 查询列表数据
*/
@RequiresPermissions("lbst:subsectionStation:view")
@RequestMapping(value = "listSubsectionData")
@ResponseBody
public Page<Subsection> listSubsectionData(Subsection subsection, HttpServletRequest request, HttpServletResponse response) {
subsection.setPage(new Page<>(request, response));
Page<Subsection> page = subsectionService.findPage(subsection);
return page;
}
5.至此,对象选择器获取参数完成
总结
至此,本文章结束