Velocity结合Ajax做的级联菜单,下拉列表

本文介绍了一个新闻管理后台创建流程的实现方式,包括新闻来源和频道的选择机制。通过JavaScript和Velocity模板引擎实现了动态加载新闻来源及其对应频道的功能。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

public ModelAndView admin(HttpServletRequest request,
			HttpServletResponse response) {
		// TODO Auto-generated method stub

		int newsWebSourceID = ReqTools.getReqInt(request, "newsWebSourceID", 0);
		String xAction = ReqTools.getReq(request, "xAction", "");

		int newsChannelID = ReqTools.getReqInt(request, "newsChannelID", 0);
		int pointNum = 0;
		String newsUrl = null;
		String title = null;
		String content = null;
		if (xAction.equals("")) {			
		
			List<NewsWebSource> newsWebSourceList = newsService
					.getAllWebSource();
			List<NewsChannel> newsChannelList = newsService
					.findNewsChannelByWebSiteID(newsWebSourceID);
			Map<Integer, List<NewsChannel>> newsChannelsMapByWebSourceID = newsService
					.getChannelsByWebSourceID();
			Map model = new HashMap();
			model.put("newsWebSourceList", newsWebSourceList);
			model.put("newsChannelList", newsChannelList);
			model.put("newsChannelsMapByWebSourceID",
					newsChannelsMapByWebSourceID);
			model.put("opera", opera);
			model.put("newsWebSourceID", newsWebSourceID);
			model.put("newsChannelID", newsChannelID);
			return new ModelAndView("news/adminNewsCreate", model);
		}
		return null;

	} 

<select id="newsWebSourceID" name="newsWebSourceID" onChange="changeWebSource();"></select>
<select name="newsChannelID" ></select> <script>
function initNewsSelect(){

#foreach($newsWebSource in $newsWebSourceList)
var oOption${velocityCount} = document.createElement("OPTION");
oOption${velocityCount}.text = "$newsWebSource.name";
oOption${velocityCount}.value = "$newsWebSource.newsWebSourceID";
$("newsWebSourceID").add(oOption${velocityCount});


#if($newsWebSource.newsWebSourceID == $newsWebSourceID)
$("newsWebSourceID").value="$newsWebSourceID";
#end


changeWebSource();

#end
}

initNewsSelect();
function   changeWebSource ()
{
$("newsChannelID").innerHTML="";
var selectWebSourceID = $("newsWebSourceID").value;

#foreach($newWebSource in $newsWebSourceList)
if ( selectWebSourceID == $newWebSource.newsWebSourceID)
{
#set($channels = $newsChannelsMapByWebSourceID.get($newWebSource.newsWebSourceID));
#foreach ($channel in  $channels )
{
var oOption${velocityCount} = document.createElement("OPTION");
oOption${velocityCount}.text = "$channel.name";
oOption${velocityCount}.value = "$channel.newsChannelID";
$("newsChannelID").add(oOption${velocityCount});

#if($channel.newsChannelID == $newsChannelID)
$("newsChannelID").value="$newsChannelID";
#end

}
#end
}
#end
}
</script>
 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值