freemarker二级联动

本文介绍了一个使用Freemarker模板引擎与JavaScript进行数据交互的例子,展示了如何将服务器端的数据动态地填充到HTML选项中,并通过JavaScript事件监听实现表单的选择更新。这个例子涉及Freemarker模板语法、JavaScript DOM操作以及数据处理。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

<#assign basePath="" />
<#assign xdttclist=xdttclist>
<#assign xdttclistTwo=xdttclistTwo>

<div class="first">
    <div>
  		选择表:<select id="exportOne" onchange="cg1()">
    	            <#list xdttclist as xd>
		                <option>${xd.tables}</option>
		            </#list>
		       </select><br>
		选择字段:<select id="exportTwo"> 
		 </select>
	</div>
</div>
 <div class="second">
		<div>
  		 选择表:<select id="importOne" onchange="cg1()">
    	            <#list xdttclistTwo as xdt>
				        <option>${xdt.tables}</option>
		            </#list>
		        </select><br>
		 选择字段:<select id="importTwo"> 
		 </select>
	</div>
</div>
var s1 = document.getElementById("exportOne");
var s2 = document.getElementById("exportTwo");
var s3 = document.getElementById("importOne");
var s4 = document.getElementById("importTwo");
var stationList = [];
var stationListTwo = []; 
function y(){
	 //获取二机组织信息
	 <#if xdttclist??>
	 	//一级组织
	 	<#list xdttclist as firstOrg>
	 		var station = new Object();
	 		station.tables = "${firstOrg.tables}";
	 		var areaList = [];
	 		//二级组织
	 		<#list firstOrg.columns as secondOrg>
	 			var secondOrg = new Object();
	 			secondOrg.name = "${secondOrg}";
	 			areaList.push(secondOrg);
	 			station.areaList = areaList;
	 		</#list>
	 		stationList.push(station);
	 	</#list>
	 </#if>
}; 

 function y2(){
	 //获取二级信息
	 <#if xdttclistTwo??>
	 	//一级组织
	 	<#list xdttclistTwo as firstOrgTwo>
	 		var stationTwo = new Object();
	 		stationTwo.tables = "${firstOrgTwo.tables}";
	 		var areaListTwo = [];
	 		//二级组织
	 		<#list firstOrgTwo.columns as secondOrgTwo>
	 			var secondOrgTwo = new Object();
	 			secondOrgTwo.name = "${secondOrgTwo}";
	 			areaListTwo.push(secondOrgTwo);
	 			stationTwo.areaListTwo = areaListTwo;
	 		</#list>
	 		stationListTwo.push(stationTwo);
	 	</#list>
	 	alert(stationListTwo.length);
	 </#if>
};  

function cg1(){
	var index = s1.selectedIndex;
	var indexTwo = s3.selectedIndex;
	var arrx = stationList[index];
	var arrxTwo = stationListTwo[indexTwo];
	s2.innerHTML = "";
	s4.innerHTML = "";
	for(var i = 0 ; i < arrx.areaList.length;i++){
		var text = arrx.areaList[i].name;
		
		s2.add(new Option(text,text)); 
	} 
	 for(var j = 0 ; j < arrxTwo.areaListTwo.length;j++){
		var textTwo = arrxTwo.areaListTwo[j].name;
		s4.add(new Option(textTwo,textTwo)); 
	}  
}
y();
y2();
cg1();

 

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值