ztree自定义按钮的显示和功能
来源:互联网 发布:linux grep命令返回值 编辑:程序博客网 时间:2024/06/04 18:58
//自定义按钮的显示和功能绑定function addDiyDom(treeId, treeNode) { var sObj = $("#" + treeNode.tId + "_span"); if (treeNode.editNameFlag || $("#addBtn_" + treeNode.tId).length > 0) return; var addStr = "<span class='fa fa-plus' id='addBtn_" + treeNode.tId + "' title='add node' onfocus='this.blur();'></span>"; var deleteStr = "<span class='fa fa-trash-o' id='deleteBtn_" + treeNode.tId + "' title='delete node' onfocus='this.blur();'></span>"; var activateStr; //根据节点数据的启用状态添加状态图标 if (treeNode.IsUsed) { activateStr = "<span class='fa fa-toggle-on' id='activateStrBtn_" + treeNode.tId + "' title='activateStr node' onfocus='this.blur();'></span>"; } else { activateStr = "<span class='fa fa-toggle-off' id='activateStrBtn_" + treeNode.tId + "' title='activateStr node' onfocus='this.blur();'></span>"; } sObj.after(addStr, deleteStr, activateStr); var btnAdd = $("#addBtn_" + treeNode.tId); if (btnAdd) btnAdd.bind("click", function () { //点击后出发新增事件 var zTree = $.fn.zTree.getZTreeObj("treeDemo"); //新增节点 var newNode = zTree.addNodes(treeNode, { id: (100 + newCount), pId: treeNode.id, name: "new node" + (newCount++) }); //新增节点真实id为空 $("#ObjId").val(""); objId = 0; //获取新增节点父节点真实Id并记录 $("#ParentId").val(treeNode.TrueId); displayPId = treeNode.tId; displayId = newNode[0].tId; zTree.selectNode(newNode[0]); switch (treeNode.TrueType) { case 1: //行业下新增分类 $("#IndustryDiv").hide(); $("#CategoryDiv").show(); $("#CourseSubjectDiv").hide(); newNode.type = 2; zTree.updateNode(newNode); break; case 2: //分类下新增科目 $("#IndustryDiv").hide(); $("#CategoryDiv").hide(); $("#CourseSubjectDiv").show(); newNode.type = 3; zTree.updateNode(newNode); break; default: break; } return false; }); var btnActivateStr = $("#activateStrBtn_" + treeNode.tId); if (btnActivateStr) btnActivateStr.on("click", function () { $.ajax({ type: "post", dataType: "json", data: { 'Type': treeNode.TrueType, 'ObjectId': treeNode.TrueId, 'IsUsed': treeNode.IsUsed }, url: "/IndustryCategory/ActivateIndustryCategory", success: function (data) { //更新ztree节点的启用状态 var treeObj = $.fn.zTree.getZTreeObj("treeDemo"); var node = treeObj.getNodeByTId(displayId); node.IsUsed = !treeNode.IsUsed; treeObj.updateNode(node); //改变选中的节点的启用禁用图标 var flag = btnActivateStr.hasClass("fa-toggle-on"); displayId = treeNode.tId; if (flag) { btnActivateStr.removeClass('fa-toggle-on').addClass('fa-toggle-off'); //删除旧class加入新class } else { btnActivateStr.removeClass('fa-toggle-off').addClass('fa-toggle-on'); //删除旧class加入新class } } }); }); var btnDelete = $("#deleteBtn_" + treeNode.tId); if (btnDelete) btnDelete.bind("click", function () { //删除选中的节点 var zTree = $.fn.zTree.getZTreeObj("treeDemo"); zTree.removeNode(treeNode); $.ajax({ type: "post", dataType: "json", data: { 'Type': treeNode.TrueType, 'ObjectId': treeNode.TrueId, }, url: "/IndustryCategory/DeleteIndustryCategory", success: function (data) { } }); });};
通过js触发ajax更新后台数据库数据,然后根据ajax回调更新ztree节点数据
ps:ajax回调刷新ztree可以通过初始化的方式 但是跟目前需求有冲突 别的地方可以考虑初始化ztree实现节点数据更新
阅读全文
1 0
- ztree自定义按钮的显示和功能
- ztree 节点单选多选按钮不显示
- ztree使用系列二(整合ztree的一些功能和demo演示)
- 具有倒计时功能的自定义按钮
- Android-自定义输入法的功能按钮
- Android-自定义输入法的功能按钮
- Android-自定义输入法的功能按钮
- 功能树Ztree的使用
- 自定义显示小红点的android Button按钮
- echarts 自定义按钮控制数据的显示
- bootstrap自定义功能按钮
- displaytag的使用方法(用于数据表格的显示和功能控制) tabledecorator实现链接按钮
- Dynamics CRM 根据用户权限不同来进行按钮的显示和隐藏的功能
- 自定义推送显示按钮
- 自定义EditText—带有清除功能,在显示多行文本时清除按钮位于整个EditText的右下角
- jquery Ztree v3.5 实例2 自定义显示在节点前的图片
- ztree显示
- 今天项目用到了权限管理展开按钮连带父节点和子节点相互关联的功能,在网上搜了搜看了ztree.js还不错,分享出来
- elasticsearch中的API
- caffe 学习之LayerParameter
- Javaweb简单博客系统-----(二)数据库建表
- XCode里遇到 #include <XXX.h>file not found的解决方案
- Python学习之旅-20
- ztree自定义按钮的显示和功能
- 《reinforcement learning:an introduction》第一章《The Reinforcement Learning Problem》总结
- POJ2912 I
- HDU1529 Cashier Employment 题解 【差分约束】【二分答案】
- SQL SERVER存储过程
- ReactNative 应用于原生应用 踩坑
- 安徽一个班37人考进清华北大,老师发来一则短信,家长沉默了
- trait
- [译]The Python Tutorial#7. Input and Output