js追加内容

(1)页面调用树形列表

@RequestMapping(value = "/minzutiyu")
public ModelAndView minzutiyu(Page page) throws Exception {
    logBefore(logger, "民族-民族扶贫");
    ModelAndView mv = this.getModelAndView();
    PageData pd = this.getPageData();
    List<Dictionaries> dlist = dictionariesService
                .listSubDictByParentId("884e7b5521854f67b187c50bada90a71"); // 获得类型
    dlist = this.readdic1(dlist);

	/*if (leixing == null || "".equals(leixing)) {
		leixing = dlist.get(0).getNAME();// 默认取类型的第一条
	} else {
		leixing = new String(leixing.getBytes("iso8859-1"), "utf-8");// 解决url中文乱码
	}
	pd.put("leixingsel", leixing);
	List<PageData> mzty = minzutiyuService.liebiao(page1);*/
    mv.setViewName("qiantai/web/ssmz/minzutiyu"); // 页面指向
    mv.addObject("dlist", dlist);
    return mv;
    }

 
    private List<Dictionaries> readdic1(List<Dictionaries> dic)
            throws Exception {
        if (dic != null && dic.size() > 0) {
            for (int i = 0; i < dic.size(); i++) {
                Dictionaries d = dic.get(i);
                List<Dictionaries> l = dictionariesService
                        .listSubDictByParentId(d.getDICTIONARIES_ID());
                if (l != null && l.size() > 0) {
                    d.setSubDict(l);
                    this.readdic1(l);
                }
            }
        }
        return dic;
    }

minzutiyu.jsp 

<div class="layui-col-xs12" style="padding: 0 16px;">
    <div class="layui-tab">
      <ul class="layui-tab-title">
	<c:choose>
		<c:when test="${not empty dlist}">
			<c:forEach items="${dlist}" var="var" varStatus="vs">
				<li class="mztylist <c:if test="${vs.index == 0}">layui-this</c:if>" leixing="${var.NAME}">${var.NAME}</li>
			 </c:forEach>
		</c:when>
		<c:otherwise>
			<tr class="main_info">
				<td colspan="100" class="center" >没有相关数据</td>
			</tr>
		</c:otherwise>
	</c:choose>
      </ul>
      <div class="layui-tab-content">
       //追加内容
      </div>
    </div>
</div>

(2)js追加

<script type="text/javascript">
     $(".mztylist").off("click").on("click",function () {
        		var lx = $(this)[0].getAttribute("leixing");
        		$.ajax({
        			type:'POST',
                	url:'<%=basePath%>qiantai/mzty?DICTIONARIES_ID='+lx,
                    dataType:'json',
                    success:function(data){
                        $(".layui-tab-content").empty();
                       		 for(var i = 0;i < data.length;i ++){
		                    	var _index = i;
		                    	var src = data[i].NEIRONG;
		                    	console.log("*************************")
		                    	console.log(src)
		                    	console.log("*************************")
		                      	var div = '<div class="t_content">'+ src +'</div>';
		                        $(".layui-tab-content").append(div);
                    		}
                    },
                    error:function(){
                        console.log('错误');
                    }
                });
        	});  
       /* 默认选中第一条并显示数据 */
        	 var lx1 = $(".mztylist")[0].getAttribute("leixing");
        	$.ajax({
      			type:'POST',
              	url:'<%=basePath%>qiantai/mzty?DICTIONARIES_ID='+lx1,
                dataType:'json',
                success:function(data){
                    $(".layui-tab-content").empty();
                       for(var i = 0;i < data.length;i ++){
		                    	var _index = i;
		                      	var div = '<div class="t_content"><p id="mingcheng">' + data[i].NEIRONG +'</p></div>';
		                        $(".layui-tab-content").append(div);
                    		}
                },
                error:function(){
                    console.log('错误');
                }
            }); 
                
    </script> 

(3)mzty方法

@RequestMapping(value = "mzty", method = RequestMethod.POST)
@ResponseBody
public List<PageData> mzty(@RequestParam(value = "DICTIONARIES_ID") String name) throws Exception {
    PageData pd = new PageData();
    pd = this.getPageData();
    System.out.println(pd);
    //服务器不需要字符转义,但是本地需要
    /*String lei = pd.getString("DICTIONARIES_ID");
    byte[] b=lei.getBytes("ISO-8859-1");//用tomcat的格式(iso-8859-1)方式去读。
    String xing=new String(b,"utf-8");
	pd.put("DICTIONARIES_ID", xing);*/
    // pd.put("LEIXING", pd.getString("DICTIONARIES_ID"));
    List<PageData> pd1 = minzutiyuService.findByName(pd);
    System.out.println(pd1);
    return pd1;
}

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值