Generate instance code for level two menus with jquery _jquery

Source: Internet
Author: User

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>
&LT;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>
&LT;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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.