所需要的jar包:
java 后台代码:
List<SuperRecord> list = new ArrayList<SuperRecord>();
list = this.resClassifyService.getChildeNodeList(nodeId);
JSONArray jsonArray = new JSONArray();
for (int i = 0; i < list.size(); i++)
{
JSONObject p_json = new JSONObject();
p_json.put("id", list.get(i).get("nodeid"));
p_json.put("name", list.get(i).get("nodename"));
jsonArray.add(p_json);
}
this.getResponse().setContentType("text/html; charset=UTF-8");
try
{
this.getResponse().getWriter().write(jsonArray.toString());
} catch (IOException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}
前台js处理:
jQuery.post("/system/classify/getDropDownList.action", {
'nodeId' : nodeId
}, function(data) {
var sec = document.getElementById("sec");
/*
* 每次动态加载先清空下拉单,再添加新的选项
*/
sec.options.length = 0;
var myobj = eval(data);
for ( var i = 0; i < myobj.length; i++) {
sec.options.add(new Option(myobj[i].name, myobj[i].id));
}
});
页面
<select id="sec" style="width: 120px;"
<option value="">请选择---</option>
</select>