[Javascript] & lt; prename & quot; code & quot; class & quot; html & quot; & gt; & lt;/pre & gt; functions on the page & lt; pre & gt; & lt;/pre & gt; & lt; prename & quot; code & quot; class & quot; javascript & quot; & [javascript]
Functions on the page
Function querySub (id, sid/* selected item */){
$.post('${path}/page/article/querySubChannelArticle.action',
{'channelId':id},function(data){
$('select[name="article.subChannel.subId"] option[value!=""]').remove();
var jsonObj = data;
for ( var i = 0; i < jsonObj.length; i++) {
var $option = $('');
$option.attr('value',jsonObj[i].subId);
if(jsonObj[i].subId === sid){
$option.attr('selected',true);
}
$option.text(jsonObj[i].subName);
$('select[name="article.subChannel.subId"]').append($option);
}
});
}
$(function(){
querySub(
,
);
});
Page code:
Level 1 topic
ListValue = "channelName"
Key = "article. subChannel. channel. channelId"
Onchange = "querySub (this. value)">
Secondary topic
Server
Server
public String querySubChannelArticle(){
HttpServletResponse response=getResponse();
HttpServletRequest request=getRequest();
response.setContentType("application/json; charset=UTF-8");
PrintWriter out =null;
try {
out = response.getWriter();
List
> list = new LinkedList
>();
if(channelId!=null && !channelId.equals("")){
Channel tmp = new Channel();
tmp.setChannelId(Integer.parseInt(channelId));
subChannelList = subChannelDAO.listSubChannel(tmp);
for(Object oo:subChannelList){
Map
obj = new HashMap
();
SubChannel c = (SubChannel)oo;
obj.put("subId", c.getSubId());
obj.put("subName", c.getSubName());
list.add(obj);
}
}
String outStr = JsonUtil.toJSONStr(list);
out.println(outStr);
}catch(Exception e){
e.printStackTrace();
}
out.flush();
out.close();
return null;
}
Actually, it's quite concise.