EasyUI tree扩展获取实心节点

Easyui tree getChecked()默认无法获取实心节点,以及扩展tree方法以实现对实心节点的获取

html:

<div style="margin:10px;">
      <a class="easyui-linkbutton" href="#" onclick="getCheckedExt()">获取checked节点(包括实心)</a>
      <a class="easyui-linkbutton" href="#" onclick="getSolidExt()">获取实心节点</a>
  </div>
 <ul id="tt1" class="easyui-tree" animate="true" checkbox="true">
  <li>
   <span>Folder</span>
   <ul>
    <li state="closed">
     <span>Sub Folder 1</span>
     <ul>
      <li>
       <span><a href="#">File 11</a></span>
      </li>
      <li>
       <span>File 12</span>
      </li>
      <li>
       <span>File 13</span>
      </li>
     </ul>
    </li>
    <li>
     <span>File 2</span>
    </li>
    <li>
     <span>File 3</span>
    </li>
    <li>File 4</li>
    <li>File 5</li>
   </ul>
  </li>
  <li>
   <span>File21</span>
  </li>
 </ul>
 
  <div id="logs"></div>

 

js:实现对获取实心节点的扩展

   

$(function(){
    //此处是扩展tree的两个方法.
    $.extend($.fn.tree.methods,{
        getCheckedExt: function(jq){//扩展getChecked方法,使其能实心节点也一起返回
            var checked = $(jq).tree("getChecked");
            var checkbox2 = $(jq).find("span.tree-checkbox2").parent();
            $.each(checkbox2,function(){
                var node = $.extend({}, $.data(this, "tree-node"), {
                    target : this
                });
                checked.push(node);
            });
            return checked;
        },
        getSolidExt:function(jq){//扩展一个能返回实心节点的方法
            var checked =[];
            var checkbox2 = $(jq).find("span.tree-checkbox2").parent();
            $.each(checkbox2,function(){
                var node = $.extend({}, $.data(this, "tree-node"), {
                    target : this
                });
                checked.push(node);
            });
            return checked;
        }
    });
});


function getCheckedExt(){
  var solids = $("#tt1").tree("getCheckedExt");
  var nodes = [];
  $.each(solids,function(){
    nodes.push(this.text);
  });
  $("#logs").text("选择的节点是(包括实心):"+nodes.join(","));

}

function getSolidExt(){
  var solids = $("#tt1").tree("getSolidExt");
  var nodes = [];
  $.each(solids,function(){
    nodes.push(this.text);
  });
  $("#logs").text("选择的实心节点是:"+nodes.join(","));
}

posted on 2013-06-23 18:29  aiyuaichou  阅读(781)  评论(0编辑  收藏  举报

导航