easyuitree点击文字打开或者闭合

    xiaoxiao2022-06-29  41

    最近使用easyui tree 发现一个问题,就是默认的展开或者闭合目录,要点击最前面的+号 或者-号 ,这个不太符合正常人的操作习惯,所以想点击文字也可以打开或者闭合。

    通过实践得到方法,仅供大家参考!

    就是加载树的时候,onclick方法中,加上一个判断,如果是关闭状态,点击非叶子节点要展开,如果是展开状态,点击非叶子节点要闭合。

    部分代码如下:

    可复制的代码:

            $("#tree").tree({             lines:true,             url:'${_currConText}/grant/view/menuTreeEasyUI.action?systemType=301',             onLoadSuccess:function(){                 $("#tree").tree('collapseAll');             },             onClick:function(node){                 if(node.state=='closed'&&(!$("#tree").tree('isLeaf',node.target))){  //状态为关闭而且非叶子节点                     $(this).tree('expand',node.target);//点击文字展开菜单                       if (node.attributes && node.attributes.url) {                           openTab(node);                     }                   }else{                       if($("#tree").tree('isLeaf',node.target)){  //状态为打开而且为叶子节点                         if (node.attributes && node.attributes.url) {                               openTab(node);                                              }                                      }else{                           $(this).tree('collapse',node.target);//点击文字关闭菜单                       }                                      }                 }         });

    转载请注明原文地址: https://ju.6miu.com/read-1125197.html

    最新回复(0)