一、tree.json文件 给要禁用掉的节点添加自定义属性:"disabled":true
[{
"id": "1",
"text": "系统管理",
"iconCls":"icon-Site",
"children": [{
"id": 11,
"text": "用户管理",
"iconCls":"icon-Device",
}, {
"id": 12,
"text": "角色管理",
"iconCls":"icon-Device",
}, {
"id": 13,
"text": "权限设置",
"iconCls":"icon-Device",
"disabled":true //要禁用的节点
}]
}]
二、加载tree.json
$("#tt").tree({
url: "tree.json",
animate: true,
method: "get",
formatter: function(node) {
var s;
if (node.disabled) {//判断该节点的disabled属性是否等于true,如果是则将字体颜色设置成灰色#D4D4D4
s = '<span class=\'tree-title\' style=\'color:#D4D4D4\' disable=true>' + node.text + '</span>';
return s;
} else {
s = '<span class=\'tree-title\' style=\'color:#000000\' disable=true>' + node.text + '</span>';
}
return s;
},
onBeforeSelect:function(node) {
if (node.disabled) {
return false;//在选中该节点前,判断该节点的disabled属性是否等于true,如果是则返回false,该节点则不会被选中
}
}
});