$('#address').combotree({ url:common.getContextPath()+'/base/getWtsdTree.do', lines:true,
来源:互联网 发布:淘宝淘口令有没有权重 编辑:程序博客网 时间:2024/06/16 17:20
easyui中combotree只能选子选项,父级不被选中
前言
前几天面试遇到一个需求(easyui中combotree只能选子选项,父级不被选中),回来特意整理下,大概的思想是如果该tree的节点被选中是判定一下是否有子节点,如果没有就说明是最终节点了,步骤如下:
1. 原来计划是看json数据的话有个children字段标识,后来用google的开发工具发现没有,但是哥们发现了一个state字段,即父级的话会自动给一个state字段,为closed或者open值,但是最终子节点没有这个字段,如下图:
a. 选个子节点瞅瞅:
b. 选个父节点瞅瞅:
2. 找到合适的事件监听,哥们在easyui的tree的api找到了这个:
onBeforeSelect:参数是node,解释:节点被选中之前触发,返回false取消选择动作(取消动作,哥们看到这就亮了,莫名的鸡冻)。
来灵感了吧,淡定淡定,开整。
代码如下(代码是easyui 1.3.2的demo里的文件路径都一样,不同的是哥们我把json数据写到js里了,懒得发布测试,这样直接可以看效果呢):
<!DOCTYPE html><html><head> <meta charset="UTF-8"> <title>ComboTree</title> <link rel="stylesheet" type="text/css" href="../../themes/default/easyui.css"> <link rel="stylesheet" type="text/css" href="../../themes/icon.css"> <script type="text/javascript" src="../../jquery-1.8.0.min.js"></script> <script type="text/javascript" src="../../jquery.easyui.min.js"></script> <script type="text/javascript" > $(function(){ $('#cc').combotree({ onBeforeSelect:function(node){ alert(node.state); if(node.state){ $("#cc").tree("unselect"); } }, data:[{ "id":1, "text":"My Documents", "children":[{ "id":11, "text":"Photos", "state":"closed", "children":[{ "id":111, "text":"Friend" },{ "id":112, "text":"Wife" },{ "id":113, "text":"Company" }] },{ "id":12, "text":"Program Files", "children":[{ "id":121, "text":"Intel" },{ "id":122, "text":"Java", "attributes":{ "p1":"Custom Attribute1", "p2":"Custom Attribute2" } },{ "id":123, "text":"Microsoft Office" },{ "id":124, "text":"Games", "checked":true }] },{ "id":13, "text":"index.html" },{ "id":14, "text":"about.html" },{ "id":15, "text":"welcome.html" }] }] }); }); </script></head><body> <input id="cc" style="width:200px;"></body></html>
实例:
$('#address').combotree({ url:common.getContextPath()+'/base/getWtsdTree.do', lines:true, animate:true, loadFilter: function(data){ if (data.success==false) { webframe.$.messager.alert('错误', data.msg, 'error'); } else { return data; } }, editable:false,required: true,missingMessage: "请选择住址",onlyLeafCheck:true, onLoadError: function(jqXHR, textStatus, errorThrown) { webframe.$.messager.alert('错误', errorThrown, 'error'); }, onBeforeSelect:function(node){ if(node.attributes[0].wtsddm.substring(4)=="00"){ $("#cc").tree("unselect"); } } });
- $('#address').combotree({ url:common.getContextPath()+'/base/getWtsdTree.do', lines:true,
- Address Lines and Buses
- 英语名词解释:Base.Address
- WinCE dll base address
- PCI中的base address
- 二义性:Common Base Class
- 如何获取AHCI base address?
- PCI 中的base address register
- combotree
- diff -y --suppress-common-lines file1 file2
- getContextPath
- CS8900 base address的确定方法
- CS8900 base address的确定方法
- CS8900 base address的确定方法
- PCI 中的base address register(转)
- 如何获取AHCI base address <二>
- 如何查看主板的base address
- Unix Sed Tutorial: Printing File Lines using Address and Patterns
- svn报的奇奇怪怪的错
- 仿今日头条,FrameLayout+RadioGroup实现联动
- 最新版勤哲Excel服务器V2017.13.0.1无限用户支持手机APP,微信,任意安装,支持后续升级
- 快速安装配置 GitLab 并汉化
- 前端代码合集
- $('#address').combotree({ url:common.getContextPath()+'/base/getWtsdTree.do', lines:true,
- HTML ionic左和右的侧滑栏
- 基于Vue、Nodejs、Socket.io的聊天应用
- java下载远程FTP文件至本地
- 'tuple' object is not callable解决方案
- PullToRefresh实现ListView的刷新,加载更多的展示
- 2006年培养学员8万人,每年增长%25,请问按此增长速度,到那一年培训学员人数将达到20万人用for,while,dowhile,实现
- 2006年培养学员8万人,每年增长%25,请问按此增长速度,到那一年培训学员人数将达到20万人用for,while,dowhile,实现
- 垃圾回收机制