论坛首页 Web前端技术论坛

dwr 二级联动

浏览 2750 次
精华帖 (1) :: 良好帖 (0) :: 新手帖 (0) :: 隐藏帖 (0)
作者 正文
   发表时间:2010-03-23  
DWR

 

je 的全站文章分类的时候二级下拉列表缺少初始化分类

 

 

<script type="text/javascript" src="dwr/engine.js"></script>
<script type="text/javascript" src="dwr/util.js"></script>
<script type="text/javascript" src="dwr/interface/personManager.js"></script>
<script type="text/javascript">
function init(){
	personManager.searchAllOrg(
		function(data){
			// [{"id":xx,"name":xx},{"id":xxx,"name":xxx},{}]
			dwr.util.addOptions("o",data,"id","name");
			searchPersons();
		}
	);
}

function searchPersons(){
	personManager.searchPersons(
		$("o").value,
		function(data){
			dwr.util.removeAllOptions("p");
			dwr.util.addOptions("p",data,"id","name");
		}
	);
}

</script>

 

 

<body onload="init()">

请选择机构:<select id="o" onchange="searchPersons()"></select> <br>
请选择人员:<select id="p"></select>

</body>

 

 

 

public class PersonManager {
	private static Map orgs = new HashMap();
	private static Map persons = new HashMap();
	
	static{
		for(int i=0; i<10; i++){
			Org org = new Org();
			org.setId(i);
			org.setName("机构"+i);
			orgs.put(org.getId(), org);
			
			List personList = new ArrayList();
			for(int j=0; j<20; j++){
				Person person = new Person();
				person.setId(j);
				person.setName("org["+org.getName()+"]下的人员[人员"+j+"]");
				personList.add(person);
			}
			persons.put(org.getId(), personList);
		}
	}
	
	public Collection searchAllOrg(){
		return orgs.values();
	}
	
	public List searchPersons(int orgId){
		return (List)persons.get(orgId);
	}
}

 

 

论坛首页 Web前端技术版

跳转论坛:
Global site tag (gtag.js) - Google Analytics