1.定义comboree
当选中的是叶子节点时,返回叶子节点;当选中的不是叶子节点时,抛错误消息,且combotree的值不改变。
EasyUI版本:jquery-easyui-1.4
<input id="cc">
$(function(){
$('#cc').combotree({
width: 200,
data: jsonData,
onBeforeSelect: function(node) {
// 判断是否是叶子节点
var isLeaf = $(this).tree('isLeaf', node.target);
if (!isLeaf) {
$.messager.show({
msg: '请选择叶子节点!'
});
// 返回false表示取消本次选择操作
return false;
}
}
});
});
2.comboree的数据源
var jsonData = [{
"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":123,
"text":"Microsoft Office"
},{
"id":124,
"text":"Games",
"checked":true
}]
},{
"id":13,
"text":"index.html"
}]
}];
3.html测试的源代码
供测试用
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Basic ComboTree - jQuery EasyUI Demo</title>
<link rel="stylesheet" type="text/css" href="../../themes/default/easyui.css">
<link rel="stylesheet" type="text/css" href="../../themes/icon.css">
<link rel="stylesheet" type="text/css" href="../demo.css">
<script type="text/javascript" src="../../jquery.min.js"></script>
<script type="text/javascript" src="../../jquery.easyui.min.js"></script>
</head>
<body>
<script>
var jsonData = [{
"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":123,
"text":"Microsoft Office"
},{
"id":124,
"text":"Games",
"checked":true
}]
},{
"id":13,
"text":"index.html"
}]
}];
$(function(){
$('#cc').combotree({
width: 200,
data: jsonData,
onBeforeSelect: function(node) {
// 判断是否是叶子节点
var isLeaf = $(this).tree('isLeaf', node.target);
if (!isLeaf) {
$.messager.show({
msg: '请选择叶子节点!'
});
// 返回false表示取消本次选择操作
return false;
}
}
});
});
</script>
<h2>Basic ComboTree</h2>
<p>Click the right arrow button to show the tree panel.</p>
<div style="margin:20px 0"></div>
<input id="cc">
</body>
</html>