jQuery EasyUI — 只选择combotree的叶子节点

1.定义comboree

当选中的是叶子节点时,返回叶子节点;当选中的不是叶子节点时,抛错误消息,且combotree的值不改变。

EasyUI版本:jquery-easyui-1.4

$(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测试的源代码

供测试用




	
	Basic ComboTree - jQuery EasyUI Demo
	
	
	
	
	


	
	

Basic ComboTree

Click the right arrow button to show the tree panel.


你可能感兴趣的:(jQuery)