treetable 用法小例
2024-09-04 17:45:27
插件地址:http://pan.baidu.com/s/1kVf0Kcfcript src="/plugins/jQuery/jQuery-2.1.4.min.js"></script>
<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">
<div class="box-body table-responsive no-padding">
<table id="treetable">
<thead>
<tr>
<th width="80px">部门名称</th> <th>规章制度</th>
<th width="120px">操作</th>
<th width="120px">操作</th>
</tr>
</thead> <tbody>
<#list treeDept as o> <#if o.parentId == '' || o.parentId == null>
<tr data-tt-id="${(o.id)!}">
<td><span class='folder'/>${o.deptName}</td>
<td>${o.deptDesc}</td>
<td>
<#if permissions?seq_contains('editDept')>
<a class="btn btn-primary btn-xs" href="/system/dept/edit/${(o.id)!}"> <i
class="fa fa-pencil-square-o"></i> 编辑</a>
<#else>-
</#if>
</td>
<td> <#if permissions?seq_contains('deleteDept')>
<a class="btn btn-danger btn-xs"
onclick="del('${(o.parentIds)!}')"
><i class="fa fa-times"></i> 删除</a>
<#else>-
</#if>
</td> </tr>
<#else>
<tr data-tt-id="${(o.id)!}" data-tt-parent-id="${(o.parentId)!}">
<td><span class='folder'/>${o.deptName}</td>
<td>${o.deptDesc}</td>
<td>
<#if permissions?seq_contains('editDept')>
<a class="btn btn-primary btn-xs" href="/system/dept/edit/${(o.id)!}">
<i
class="fa fa-pencil-square-o"></i> 编辑</a>
<#else>-
</#if>
</td>
<td>
<#if permissions?seq_contains('deleteDept')>
<a class="btn btn-danger btn-xs"
onclick="del('${(o.parentIds)!}')"
><i class="fa fa-times"></i> 删除</a>
<#else>-
</#if>
</td> </tr>
</#if>
</#list>
</tbody>
<!--t--> </table>
</div> <script src="/plugins/jquery-treetable-master/jquery.treetable.js"></script>
<script>
function del(parentIds) {
if (confirm("您确定要删除该条记录吗")) {
$.ajax({
type: "POST",
url: "/system/dept/delete",
data: {parentIds: parentIds}, // 省级别
dataType: 'json',
success: function (data) {
alert(data.msg);
if (data.code == 0) {
window.location.href = "/system/dept/list/1"
} debugger
}, 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>
/**
* 执行新增
*/
@Permission("addDept")
@Log("保存部门")
@RequestMapping("/doSave")
public String doSave(SysDept dept) {
if (StringUtils.isNotBlank(dept.getId())) { //编辑
sysDeptService.doUpdate(dept);
} else { //新增
dept.setId(CommonUtil.UUID());
int recond = sysDeptService.doSave(dept);
}
return redirectTo("/system/dept/list/1");
}
@Override
public int doSave(SysDept dept) {
String id = dept.getId();
String parentIds = dept.getParentIds();
parentIds += "/" + id;
dept.setParentIds(parentIds);
int record = baseMapper.add(dept);
return record;
} @Override
public int doUpdate(SysDept dept) {
String id = dept.getId();
String parentIds = dept.getParentIds(); parentIds += "/" + id;
dept.setParentIds(parentIds);
int record = baseMapper.doUpdate(dept);
return record; }
<select id="selectDeptList" resultMap="BaseResultMap">
SELECT id,deptName,deptDesc,parentId, parentName,parentIds,sorts
FROM sys_dept
where delFlag=0
<if test="dept!=null and dept.deptName != null and dept.deptName != ''">
and deptName like concat('%',#{dept.deptName},'%')
</if>
<if test="dept!=null and dept.parentIds != null and dept.parentIds != ''">
and parentIds like concat('%',#{dept.parentIds},'%')
</if> ORDER BY
parentIds
</select>
<insert id="add"
parameterType="com.vacomall.entity.SysDept">
INSERT INTO sys_dept (
id,
deptName,
deptDesc,
parentId,
parentName,
sorts,
deptCode,
parentIds
)
VALUES
(
#{id,jdbcType=VARCHAR},
#{deptName,jdbcType=VARCHAR},
#{deptDesc,jdbcType=VARCHAR},
#{parentId,jdbcType=VARCHAR},
#{parentName,jdbcType=VARCHAR},
#{sorts,jdbcType=TINYINT},
#{deptCode,jdbcType=VARCHAR},
#{parentIds,jdbcType=VARCHAR}
)
</insert> <update id="doUpdate" parameterType="com.vacomall.entity.SysDept">
update sys_dept
set
deptName = #{deptName,jdbcType=VARCHAR},
deptDesc = #{deptDesc,jdbcType=VARCHAR},
parentId = #{parentId,jdbcType=VARCHAR},
parentName = #{parentName,jdbcType=VARCHAR},
parentIds = #{parentIds,jdbcType=VARCHAR},
sorts = #{sorts,jdbcType=TINYINT},
deptCode = #{deptCode,jdbcType=VARCHAR} where id = #{id,jdbcType=VARCHAR}
</update>
最新文章
- u盘安装CENTOS后,启动missing operating system ,只能用U盘才能启动系统
- 关于ArrayList 容量问题
- P6 EPPM 安装与配置指南 16 R1 2016.4
- 用SQL打印乘法口诀表
- Libvirt 网络管理
- Ubuntu 14.04 LTS 与Kylin
- html5桌面通知,notification的使用,右下角出现通知框
- WINDOWS下的SALT-MINION安装流水图
- STM8S 独立看门狗配置及使用
- AlphaBlend參数BLENDFUNCTION
- 转:设置HtmlUnitDriver代理及处理用户验证有关问题
- 框架应用:Mybatis(二) - 动态SQL
- 声音变调算法PitchShift(模拟汤姆猫) 附完整C++算法实现代码
- oracle 游标简单示例
- ALU底层方法及计算机整数加减乘除模拟
- 总结描述用户和组管理类命令的使用方法,系统用户相关信息,取出主机IP地址
- WindowsPE权威指南 第二章 小工具 PEInfo代码的C语言实现
- 一道搜索题【2013 noip提高组 DAY2 t3】华容道
- 20175311 2018-2019-2 《Java程序设计》第1周学习总结
- vim鼠标模式打开与关闭
热门文章
- selenium--Xpath定位
- 浏览器window产生的缓存九种解决办法
- PAT (Basic Level) Practise (中文)-1027. 打印沙漏(20)
- bootstrap 翻页(对齐的链接)
- ios之UISearchBar
- xhEditor编辑器上传图片到 OSS
- [LUOGU] P2759 奇怪的函数
- MySql的基操勿六
- (17)zabbix自定义用户key与参数User parameters
- 总线(bus);设备(devices);驱动(drivers)