(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;
}