Javascript
Functions in a page
Copy Code code as follows:
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> ');
$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 (<s:property value= ' article.subChannel.channel.channelId '/>,<s:property value= ') Article.subChannel.subId '/>);
});
Page code:
Copy Code code as follows:
<tr>
<th> level Columns </th>
<TD valign= "Middle" >
<s:select id= ' _channel ' list= ' channellist ' listkey= ' channelid '
Listvalue= "ChannelName"
key= "Article.subChannel.channel.channelId"
Onchange= "Querysub (this.value)" ></s:select>
</td>
</tr>
<tr>
<th> Level Two column </th>
<TD valign= "Middle" >
<s:select name= ' article.subChannel.subId ' list= ' {} ' headerkey= ' "headervalue="-Please select-"></s:select>
<!--<s:property value= "Article.subChannel.subName"/>
--></td>
</tr>
Server-side
Copy Code code as follows:
Public String querysubchannelarticle () {
HttpServletResponse Response=getresponse ();
HttpServletRequest request=getrequest ();
Response.setcontenttype ("Application/json; Charset=utf-8 ");
PrintWriter out =null;
try {
out = Response.getwriter ();
list<map<string,object>> list = new linkedlist<map<string,object>> ();
if (Channelid!=null &&!channelid.equals ("")) {
Channel tmp = new Channel ();
Tmp.setchannelid (Integer.parseint (channelid));
Subchannellist = Subchanneldao.listsubchannel (TMP);
for (Object oo:subchannellist) {
map<string,object> obj = new hashmap<string,object> ();
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;
}
It's pretty neat, actually.