1. 程式人生 > >在EasyUI實現點擊有子節點的文字時展開但不選中,點擊最終子節點才選中的功能

在EasyUI實現點擊有子節點的文字時展開但不選中,點擊最終子節點才選中的功能

nload 容易 事件 data strong 中項 eight spa 清除

最近做的項目中,總是會遇到需要實現點擊樹目錄的有子節點時展開目錄,點擊最終子節點才實現選中的功能的需求。下邊我就直接黏貼一下代碼出來吧,非常容易看懂,關鍵的就是在選中事件中加一個判斷。

$(‘#RepairTID‘).combotree({
url: ‘/RepairSub/GetRepTypeZ/?userRole=5‘,
required: true,
panelHeight: ‘auto‘,
onLoadSuccess: function (node, data) {
if (data != null) {

    //加載時全部展開

$(‘#RepairTID‘).combotree(‘tree‘).tree("collapseAll");

    //設置默認選中項
$(‘#RepairTID‘).combotree(‘setValue‘, { id: 0 });
}
},
onSelect: function (node) {
var tree = $(this).tree;
//選中的節點是否為葉子節點,如果不是葉子節點,清除選中

$(this).tree(node.state === ‘closed‘ ? ‘expand‘ : ‘collapse‘, node.target);


var isLeaf = tree(‘isLeaf‘, node.target);
if (!isLeaf) {
//清除選中
//$(‘#Rep_AreaID‘).combotree(‘clear‘);
$("#RepairTID").tree("unselect");
}
}
});

在EasyUI實現點擊有子節點的文字時展開但不選中,點擊最終子節點才選中的功能