<!DOCTYPE html>
<html><head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>分类列表</title> <meta name="keywords" content=""> <meta name="description" content=""><link rel="shortcut icon" href="favicon.ico"> <link href="__CSS__/bootstrap.min.css?v=3.3.6" rel="stylesheet">
<link href="__CSS__/font-awesome.css?v=4.4.0" rel="stylesheet"> <link href="__CSS__/animate.css" rel="stylesheet"> <link href="__CSS__/style.css?v=4.1.0" rel="stylesheet"> <style type="text/css"> .tree { min-height:20px; padding:19px; margin-bottom:20px; background-color:#fbfbfb; border:1px solid #999; -webkit-border-radius:4px; -moz-border-radius:4px; border-radius:4px; -webkit-box-shadow:inset 0 1px 1px rgba(0, 0, 0, 0.05); -moz-box-shadow:inset 0 1px 1px rgba(0, 0, 0, 0.05); box-shadow:inset 0 1px 1px rgba(0, 0, 0, 0.05)}.tree li { list-style-type:none; margin:0; padding:10px 5px 0 5px; position:relative}.tree li::before, .tree li::after { content:''; left:-20px; position:absolute; right:auto}.tree li::before { border-left:1px solid #999; bottom:50px; height:100%; top:0; width:1px}.tree li::after { border-top:1px solid #999; height:20px; top:25px; width:25px}.tree li span { -moz-border-radius:5px; -webkit-border-radius:5px; border:1px solid #999; border-radius:5px; display:inline-block; padding:3px 8px; text-decoration:none}.tree li.parent_li>span { cursor:pointer}.tree>ul>li::before, .tree>ul>li::after { border:0}.tree li:last-child::before { height:30px}.tree li.parent_li>span:hover, .tree li.parent_li>span:hover+ul li span { background:#eee; border:1px solid #94a0b4; color:#000}</style> </head><body class="gray-bg">
<div class="wrapper wrapper-content animated fadeInRight"> <div class="row"> <div class="col-sm-12"> <div class="ibox float-e-margins"> <div class="ibox-title"> <h5>分类列表</h5></div>
<div class="ibox-content"> <div class="tree well"><ul id="rootUL">
</ul>
</div> </div> </div> </div></div>
</div><!-- 全局js -->
<script src="__JS__/jquery.min.js?v=2.1.4"></script> <script src="__JS__/bootstrap.min.js?v=3.3.6"></script></body>
</html>
<script>window.οnlοad=function(){ $.ajax({ url:"{:url('index/cate_ajax')}", dataType:"json", type:"GET", success:function (data){ tree(data); $('.tree li:has(ul)').addClass('parent_li').find(' > span').attr('title', '关闭'); $('.tree li.parent_li > span').on('click', function (e) { var children = $(this).parent('li.parent_li').find(' > ul > li'); if (children.is(":visible")) { children.hide('fast'); $(this).attr('title', '展开').find(' > i').addClass('icon-plus-sign').removeClass('icon-minus-sign'); } else { children.show('fast'); $(this).attr('title', '关闭').find(' > i').addClass('icon-minus-sign').removeClass('icon-plus-sign'); } e.stopPropagation(); }); } });}function tree(data) { for (var i = 0; i < data.length; i++) { var data2 = data[i]; if (data[i].icon == "icon-th") { $("#rootUL").append("<li data-name='" + data[i].code + "'><span><i class='" + data[i].icon + "'></i> " + data[i].name + "</span></li>"); } else { var children = $("li[data-name='" + data[i].parentCode + "']").children("ul"); if (children.length == 0) { $("li[data-name='" + data[i].parentCode + "']").append("<ul></ul>") } $("li[data-name='" + data[i].parentCode + "'] > ul").append( "<li data-name='" + data[i].code + "'>" + "<span>" + "<i class='" + data[i].icon + "'></i> " + data[i].name + "</span>" + "</li>") } for (var j = 0; j < data[i].child.length; j++) { var child = data[i].child[j]; var children = $("li[data-name='" + child.parentCode + "']").children("ul"); if (children.length == 0) { $("li[data-name='" + child.parentCode + "']").append("<ul></ul>") } $("li[data-name='" + child.parentCode + "'] > ul").append( "<li data-name='" + child.code + "'>" + "<span>" + "<i class='" + child.icon + "'></i> " + child.name + "</span>" + "</li>") var child2 = data[i].child[j].child; tree(child2) } tree(data[i]); }}
</script>