Authored by FengRuwei

type tree show

... ... @@ -6,5 +6,6 @@ package com.ui.contants;
public class HttpUriContants {
public static String TEST_GET_URI = "/test/get";
public static String GET_ALL_TYPE = "/type/query";
}
... ...
... ... @@ -31,7 +31,16 @@ public class HttpRestClient {
try {
return restTemplate.getForObject(systemConfig.getServiceUrl() + uri, responseType,map);
} catch (Exception e) {
logger.error("getForObject failed!url:"+uri, e);
logger.error("getForObject failed!url: "+uri, e);
return null;
}
}
public <T> T defaultGet(String uri, Class<T> responseType) {
try {
return restTemplate.getForObject(systemConfig.getServiceUrl() + uri, responseType);
} catch (Exception e) {
logger.error("getForObject failed!url: "+uri, e);
return null;
}
}
... ...
... ... @@ -38,7 +38,7 @@
<div id="sidebar">
<ul>
<li class="active"><a href="#"><i class="icon icon-home"></i> <span>Dashboard</span></a></li>
<li><a href="#" onclick="clickMenuToPage(this)" ><i class="icon icon-th"></i> <span>Tables</span></a></li>
<li><a href="#" onclick="clickMenuToPage('/jsp/table.jsp')" ><i class="icon icon-th"></i> <span>Tables</span></a></li>
<li><a href="#" onclick="clickMenuToPage('/jsp/host/hostInfoList.jsp')" ><i class="icon icon-th"></i> <span>主机信息</span></a></li>
</ul>
</div>
... ...
... ... @@ -86,35 +86,15 @@
});
});
//模拟数据
var jsonData = [
{"id":"1","name":"父节点1","url":"www.baidu.com","pid":"0"},
{"id":"4","name":"父节点11","url":"","pid":"1"},
{"id":"14","name":"父节点112","url":"","pid":"4"},
{"id":"5","name":"父节点12","url":"","pid":"1"},
{"id":"6","name":"父节点13","url":"","pid":"1"},
{"id":"2","name":"父节点4","url":"","pid":"0"},
{"id":"7","name":"父节点41","url":"","pid":"2"},
{"id":"8","name":"父节点42","url":"","pid":"2"},
{"id":"9","name":"父节点43","url":"","pid":"2"},
{"id":"3","name":"父节点5","url":"","pid":"0"},
{"id":"10","name":"父节点51","url":"","pid":"3"},
{"id":"13","name":"父节点111","url":"","pid":"4"},
{"id":"11","name":"父节点52","url":"","pid":"3"},
{"id":"12","name":"父节点53","url":"","pid":"3"}
] ;
//主方法,运用递归实现
function createTree(jsons,pid){
if(jsons != null){
var ul = '<ul class="" style="width: 250px;" >' ;
for(var i=0;i<jsons.length;i++){
if(jsons[i].pid == pid){
ul += '<input type="checkbox" name="checkBox" value='+jsons[i].id+' style="float: left;margin-top: 6px;width:10px;height:10px;"><li class="tree" value='+jsons[i].id+'>' + jsons[i].name + "</li>" ;
ul += createTree(jsons,jsons[i].id);
if(jsons[i].typeParentId == pid){
ul += '<input type="checkbox" name="checkBox" value='+jsons[i].typeId+' style="float: left;margin-top: 6px;width:10px;height:10px;"><li class="tree" value='+jsons[i].typeParentId+'>' + jsons[i].typeName + "</li>" ;
ul += createTree(jsons,jsons[i].typeId);
}
}
ul += "</ul>" ;
... ... @@ -123,14 +103,22 @@
}
$(function(){
var ul = createTree(jsonData,0) ;
$("#continer").append(ul) ;
//控制菜单的隐藏显示
$("ul[class] li").each(function(){
$(this).click(function(){
$(this).next().toggle();
$.get("type/all", function (data,state) {
console.log(state)
var jsonData=JSON.parse(data);
var ul = createTree(jsonData,0) ;
$("#continer").append(ul) ;
//控制菜单的隐藏显示
$("ul[class] li").each(function(){
$(this).click(function(){
$(this).next().toggle();
}) ;
}) ;
}) ;
});
}) ;
</script>
... ...