页面中的函数
复制代码 代码如下:
function querysub(id,sid/*选中的项*/){
$.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 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(,);
});
页面代码:
复制代码 代码如下:
一级栏目
listvalue=channelname
key=article.subchannel.channel.channelid
onchange=querysub(this.value)>
二级栏目
服务器端
复制代码 代码如下:
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;
}
其实蛮简洁的
