用jQuery生成两级菜单的实例代码
Javascript页面中的函数
复制代码代码如下所示:
功能querysub(ID,希德 / * * / {选定的项目)
美元。后($ {路} /页面/文章/ querysubchannelarticle行动,
{ 'channelid:ID功能(数据){ },
($ 'select {名称=的文章。子信道。ID} = {值选项!();
无功jsonobj =数据;
对于(var i = 0;i < jsonobj.length;i++){
选项$ =($);
option.attr美元(币值,jsonobj {我},ID);
如果(jsonobj {我}。ID = SID){
option.attr美元(选中的,真的);
}
option.text美元(jsonobj {我}。子名字);
($ 'select {名称=的文章。子信道。ID。追加)($);
}
});
}
$(函数(){())
QuerySub(,);
});
网页代码:
复制代码代码如下所示:
第一类栏目
<:id = '_channel'list =channellistlistkey =channelid
listvalue =channelname
关键= 的文章。子信道。信道。channelid
变化=querysub(的价值)>
两级柱
-->
服务器端
复制代码代码如下所示:
公共字符串querysubchannelarticle(){
httpservletresponse反应= GetResponse();
HttpServletRequest请求= GetRequest();
response.setcontenttype(应用程序/ JSON;字符集= UTF-8);
PrintWriter = null;
{试
= response.getwriter();
列表>列表=新的LinkedList >();
如果(channelid!= null!channelid.equals()){
通道=新通道();
Tmp.setChannelId(integer.parseint(channelid));
subchannellist = subchanneldao.listsubchannel(TMP);
为(面向对象方法:subchannellist){
地图目标=新HashMap();
子信道(信道)的面向对象的C =;
obj.put(ID
obj.put(子名字
list.add(obj);
}
}
字符串outstr = jsonutil.tojsonstr(名单);
out.println(outstr);
} catch(异常E){
E.printStackTrace();
}
Out.flush();
Out.close();
返回null;
}
这很简单。