首页 > 代码库 > 前台动态构造下拉列表

前台动态构造下拉列表

1、后台返回一个list,并封装成json;

 public void loadDep() {

// 根据单位获取所有部门信息

tblUserDepartmentList = (List<TblUserDepartment>)workResService.find("From             TblUserDepartment t where t.delFlag =‘" + Constants.DELFLAGA + "‘ and             t.userUnitId =‘"+unitId+"‘ order by t.sort");

// 把list转换成json格式

this.responseAJAX(JSONArray.fromObject(tblUserDepartmentList).toString(),         getResponse());

 }

2、前台接收处理:

<script type="text/javascript">

    function loadDep1() {

  var unitId = $("#hidden_selectedUserUnit").val();

        // 赋值之前把上次的值清空

$("#depSel").empty();

$.post(‘workRes_loadDep.action‘,{"unitId":unitId},function(result){

result = $.parseJSON(result);

$.each(result,function(i){

 $("#depSel").append("<option     value=http://www.mamicode.com/‘"+result[i].userDepartmentId+"‘>"+result[i].name+"</option>");  

  });

});

}


</script>

jsp 表单为:

  <select id="depSel" name="tblWrPeople.userDepartmentId" style="width: 130px">

   </select>


本文出自 “画江湖之不良人” 博客,谢绝转载!

前台动态构造下拉列表