插件地址:http://pan.baidu.com/s/1kVf0Kcf
<script src="/plugins/jQuery/jQuery-2.1.4.min.js"></script>
<#include "/common/head.html"/> <#include "/common/js.html"> <link rel="stylesheet" type="text/css" href="/plugins/jquery-treetable-master/css/screen.css"> <link rel="stylesheet" type="text/css" href="/plugins/jquery-treetable-master/css/jquery.treetable.css"> <link rel="stylesheet" type="text/css" href="/plugins/jquery-treetable-master/css/jquery.treetable.theme.default.css"> <style type="text/css"> </style> <!-- Content Header (Page header) --> <section class="content-header"> <h1> <small>财务管理 > 财务分类管理</small> </h1> </section> <section class="content"> <!-- Your Page Content Here --> <div class="row"> <div class="col-xs-12"> <div class="box"> <input type="button" value="添加一级分类" onclick="addYJFL()"> <table id="treetable"> <thead> <tr> <th>分类名称</th> <th>操作</th> </tr> </thead> <tbody> <#list dataList as o> <#if o.parentId == 1> <tr data-tt-id="${(o.id)!}"> <!--<td></span>${(o.id)!}</td>--> <td><span class=‘folder‘></span>${(o.classifyName)!}</td> <!--<td>${(o.parentId)!}</td>--> <td> <button onclick="edit(‘${(o.id)!}‘)">编辑</button> <button onclick="delte(‘${(o.id)!}‘)">删除</button> <button onclick="addEJFL(‘${(o.id)!}‘)">添加二级分类</button> </td> </tr> <#else> <tr data-tt-id="${(o.id)!}" data-tt-parent-id="${(o.parentId)!}"> <!--<td><span class=‘file‘></span>${(o.id)!}</td>--> <td><span class=‘file‘></span>${(o.classifyName)!}</td> <!--<td>${(o.parentId)!}</td>--> <td> <button onclick="edit(‘${(o.id)!}‘)">编辑</button> <button onclick="delte(‘${(o.id)!}‘)">删除</button> </td> </tr> </#if> </#list> </tbody> </table> </div> </div> </div> <!--添加一级分类--> <div class="modal fade" id="detailModel"> <div class="modal-dialog modal-full " style="z-index:9999;"> <div class="modal-content" style="width: 400px;height: 200px;margin-left: -50px"> <div class="modal-header"> <button type="button" class="close" data-dismiss="modal" aria-label="Close"> <span aria-hidden="true">×</span> </button> <h4 class="modal-title" id="supplierTitleInfo">添加分类</h4> </div> <div class="form-group"> <label for="classifyName" class="col-sm-2 control-label"> 分类名称</label> <div class="col-sm-10"> <input type="hidden" id="flagId" name="flagId"> <input type="hidden" id="classifyId" name="classifyId"> <input type="text" id="classifyName" name="classifyName" class="form-control" style="width:200px;" placeholder="分类名称" data-rule="分类名称必填:required;"> </div> </div> <div class="modal-footer"> <button type="button" class="btn btn-default" onclick="queding()">确定 </button> <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button> </div> </div> </div> </div> </section> <!-- <table id="treetable"> <tr data-tt-id="1"> <td>Parent</td> </tr> <tr data-tt-id="2" data-tt-parent-id="1"> <td>Child</td> </tr> </table>--> <script src="/plugins/jquery-treetable-master/jquery.treetable.js"></script> <script> function addYJFL() { $(‘#flagId‘).val("addyjfl"); $("#classifyName").val(""); $(‘#classifyId‘).val(""); $("#detailModel").modal(‘show‘); } function queding() { var flagId = $(‘#flagId‘).val(); console.log(flagId); if (flagId == "edit") { // $.ajax({ type: "POST", url: "/account/classify/editYJFL", data: { classifyName: $("#classifyName").val(), id: $(‘#classifyId‘).val() }, dataType: ‘json‘, success: function (data) { $("#detailModel").modal(‘hide‘); alert("修改成功"); window.location.reload(); }, error: function () { alert("错了"); } }); } else if (flagId == "addyjfl") { // $.ajax({ type: "POST", url: "/account/classify/addYJFL", data: {classifyName: $("#classifyName").val()}, dataType: ‘json‘, success: function (data) { $("#detailModel").modal(‘hide‘); alert("添加成功"); window.location.reload(); }, error: function () { alert("错了"); } }); } else if (flagId == "addEJFL") { $.ajax({ type: "POST", url: "/account/classify/addEJFL", data: { classifyName: $("#classifyName").val(), parentId: $(‘#classifyId‘).val() }, dataType: ‘json‘, success: function (data) { $("#detailModel").modal(‘hide‘); alert("添加成功"); window.location.reload(); }, error: function () { alert("错了"); } }); } } function addEJFL(id) { $(‘#flagId‘).val("addEJFL"); $(‘#classifyId‘).val(id); $("#classifyName").val(""); $("#detailModel").modal(‘show‘); } function edit(id) { $.ajax({ type: "POST", url: "/account/classify/getYJFL", data: {id: id}, dataType: ‘json‘, success: function (data) { $(‘#classifyId‘).val(data[0].id); $(‘#classifyName‘).val(data[0].classifyName); $(‘#flagId‘).val("edit"); $("#detailModel").modal(‘show‘); }, error: function () { alert("错了"); } }); } function delte(id) { alert("确定删除?"); $.ajax({ type: "POST", url: "/account/classify/delte", data: {id: id}, dataType: ‘json‘, success: function (data) { window.location.reload(); }, error: function () { alert("错了"); } }); } </script> <script> $("#treetable").treetable({ expandable: true,// 展示 initialState: "expanded",//默认打开所有节点 stringCollapse: ‘关闭‘, stringExpand: ‘展开‘, onNodeExpand: function () {// 分支展开后的回调函数 var node = this; //判断当前节点是否已经拥有子节点 var childSize = $("#treetable").find("[data-tt-parent-id=‘" + node.id + "‘]").length; if (childSize > 0) { return; } var data = "pageId=" + node.id; // Render loader/spinner while loading 加载时渲染 $.ajax({ loading: false, sync: false,// Must be false, otherwise loadBranch happens after showChildren? // url: context + "/document/loadChild.json", data: data, success: function (result) { if (0 == result.code) { if (!com.isNull(result.body)) { if (0 == eval(result.body[‘chilPages‘]).length) {//不存在子节点 var $tr = $("#treetable").find("[data-tt-id=‘" + node.id + "‘]"); $tr.attr("data-tt-branch", "false");// data-tt-branch 标记当前节点是否是分支节点,在树被初始化的时候生效 $tr.find("span.indenter").html("");// 移除展开图标 return; } var rows = this.getnereateHtml(result.body[‘chilPages‘]); $("#treetable").treetable("loadBranch", node, rows);// 插入子节点 $("#treetable").treetable("expandNode", node.id);// 展开子节点 } } else { alert(result.tip); } } }); } }); </script>
时间: 2024-11-02 16:57:46