页面:
<tr>
<td class="label" width="300" >作业计划项模板</td>
<td>
<select name="modelId" size="1" style="width: 6.8cm;" id="s1" subid="s2" onchange="javascript:chooseFunction();">
<option value="">请选择</option>
<%for(int i=0;i<modellist.size();i++){
TawwpModelVO tawwpModelVO = (TawwpModelVO)modellist.get(i);%>
<option value='<%=tawwpModelVO.getId()%>'><%=tawwpModelVO.getModelName()%></option>
<% }%>
</select>
</td>
</tr>
<tr>
<td class="label" >
作业计划项名称
</td>
<td>
<input id="f1" type="hidden" style="width: 6.8cm;">
<select name="functionId" size="1" style="width: 6.8cm;" id="s2" >
</select>
</td>
</tr>
前台页面的调用:
前台接收到 json 的处理
Ext.Ajax.request({
method:'post',
url: '../assessmodel/functionContent.do?functionId='+id,
success: function(json){
var aa = json.responseText;
var data = eval('('+aa+')');
var bb=data.rows;
var sele = document.getElementById("s2");
sele.innerHTML = "";
var option2 = document.createElement('option');
option2.value ="";
option2.text= "请选择";
option2.selected="selected";
sele.add(option2);
for(var i=0;i<bb.length;i++){
var option = document.createElement('option');
option.value = bb[i].id;
option.text= bb[i].name;
sele.add(option);
}
},
failure : function() {
alert("加载数据异常");
}
});
后台的处理:
private ActionForward findFunction(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response) {
IAssessModelMgr assessModelMgr = (IAssessModelMgr) getBean("assessModelMgr");
String id = request.getParameter("functionId");
List assList =null;
List nList = new ArrayList(); try {
assList = assessModelMgr.findFunctionList(id);
//request.setAttribute("functionList",assList);
for(int i=0;i<assList.size();i++){
Map map = new HashMap();
TawwpModelContentVO fu = new TawwpModelContentVO();
fu=(TawwpModelContentVO)assList.get(i);
map.put("id", fu.getContendid());
map.put("name",fu.getName());
nList.add(map);
}
response.setContentType("text/xml;charset=UTF-8"); // 返回JSON对象
response.getWriter().print(JSONUtil.list2JSON(nList));
return null;
} catch (Exception e) {
//generalError(request, e);
ActionMessages messages = new ActionMessages();
messages.add(ActionMessages.GLOBAL_MESSAGE, new ActionMessage(
"submit.title.failure"));
saveMessages(request, messages);
return mapping.findForward("failure");
}
}