87,923
社区成员
发帖
与我相关
我的任务
分享
<html>
<head>
<script type="text/javascript" src="https://ss1.bdstatic.com/5eN1bjq8AAUYm2zgoY3K/r/www/cache/static/protocol/https/jquery/jquery-1.10.2.min_f2fb5194.js"></script>
</head>
<body>
<div id="nestable_dep" class="nestable-white dd"></div>
<script type="text/javascript">
jQuery(document).ready(function() {
var Depelm = $("#nestable_dep");
var data=[{"SystemUsers":[],"Id":1,"Code":"123","Name":"123","ParentId":1,"Description":"","State":1},{"SystemUsers"
:[],"Id":2,"Code":"1232","Name":"123","ParentId":1,"Description":"","State":1},{"SystemUsers":[],"Id"
:3,"Code":"12321","Name":"1231","ParentId":2,"Description":"","State":1},{"SystemUsers":[],"Id":4,"Code"
:"2343","Name":"2343","ParentId":2,"Description":"","State":1},{"SystemUsers":[],"Id":5,"Code":"222"
,"Name":"222","ParentId":2,"Description":"","State":1},{"SystemUsers":[],"Id":6,"Code":"qwe","Name":"www"
,"ParentId":2,"Description":"","State":1}]
var dom = document.createElement("ol");
$(dom).addClass("dd-list");
Depelm.append(dom);
$.each(data, function(index, value) {
var item = document.createElement("li");
$(item).addClass("dd-item").attr("data-id", value.Id);
var itemDiv = document.createElement("div");
$(itemDiv).addClass("dd-handle").text(value.Name);
$(item).append(itemDiv);
var hasChild = Depelm.find("[data-id='" + value.ParentId + "']");
if (hasChild.length > 0) {
var cdol = $(hasChild[0]).children("ol:first");
if (cdol.length > 0) {
$(cdol[0]).append(item);
} else {
var cpol = $(hasChild[0]);
cpol.append(dom);
cpol.children("ol:first").append(item);
}
} else {
Depelm.children("ol:first").append(item);
}
});
});
</script>
</body>
</html>