easyUI:使comboTree组合树根节点不可点击
作者:神秘网友
发布时间:2020-09-12 19:46:14
easyUI:使comboTree组合树根节点不可点击
easyUI:使comboTree组合树根节点不可点击各个元素的点击事件其实是继承的父元素div的,可以使用开发者工具查看:
大概思路:我猜想可能源码是根据元素类型再做具体的动作,我们尽量不去改源码,所以让我们要控制的子元素不继承父元素的事件。所以在加载成功后,通过onLoadSuccess方法,取到各个元素,取消他事件的冒泡迭代。
疑问:为毛onLoadSuccess:function(node,data)的node获取到是空的,为什么,为什么?如果有大神知道还望不吝赐教!
代码:
// 加载分类数据
$("#1").combotree({
lines:true,// 显示树线条
onBeforeSelect:function(node){ // 节点被选中前触发,返回 false 则取消选择动作(但是返回false,下拉选项依旧会关闭)
if(node.attributes=="root"){
return false;
}else{
return true;
}
// 加载存货编码列表
},
onLoadSuccess:function(node,data){// 数据加载成功后
$(".tree-title").each(function(){
var b = $(this).prev().hasClass("tree-folder");// 判断元素是否为根节点或子节点(通过文件图标判断)
if(b){
$(this).attr("style","display:inline-block;width:100%;");// 防止点击到后面的空白区域,让span把区域填满
$(this).prev().click(function(e){
e.stopPropagation();// 取消事件的冒泡迭代
});
$(this).click(function(e){
e.stopPropagation();// 取消事件的冒泡迭代
});
}
});
}
});
// 加载数据
$("#1").combotree('loadData',
[{"id":1,"text":"1234",attributes:"root","children":[{attributes:"children","id":3,"text": 'node241'},{attributes:"children","id":4,"text": 'node242'}]},
{"id":2,"text":"1235",attributes:"root","children":[{attributes:"children","id":3,"text": 'node241'},{attributes:"children","id":4,"text": 'node242'}]}
]
);