ArrayList 和Object的转换
后台业务
public ArrayList getSelect(){
commandContext.clear();
commandContext.setCommandName("getSystemCommonVOs");
commandContext.setServiceName("systemCommonService");
SystemCommonVO vo = new SystemCommonVO();
vo.setField("*");
vo.setTablename("T_Util");
commandContext.setCommandParams(new Object [] {vo}, new Class [] {SystemCommonVO.class});
ArrayList rs =(ArrayList)this.executeCommandContext().getResult();
return rs;
}
前台js和页面
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">
<title>My JSP 'MyJsp' starting page</title>
<script type="text/javascript" src="<%=request.getContextPath()%>/dwr/engine.js"></script>
<script type="text/javascript" src="<%=request.getContextPath()%>/dwr/util.js"></script>
<script type="text/javascript" src="<%=request.getContextPath()%>/dwr/interface/showall.js"></script>
<script type="text/javascript">
function setProValue(){
showall.getSelect(callback);
}
function callback(data) {
DWRUtil.addOptions("conId", data,data.U_Name);
}
</script>
</head>
<body>
<select id="conId" name="controy" >
</select>
<button type="submit" onclick="setProValue()"></button>
</body>
</html>
每次运行下拉列表都是显示的 object Object
求大神开导。。。。
------解决方案--------------------
这句话有问题:DWRUtil.addOptions("conId", data,data.U_Name);
改成:DWRUtil.addOptions("conId", data,"U_Name","U_Name");
这个方法的后面两个参数,应该填数据库的两个列名,对应就是你下拉框要显示的文字和真实的值。