欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

Easyui和zTree兩種方式分別實(shí)現(xiàn)樹形下拉框

 更新時(shí)間:2017年08月04日 16:22:58   作者:Annie-ax  
最近工作中需要用到樹形下拉框,因?yàn)轫?xiàng)目中樹形結(jié)構(gòu)使用的是zTree,效果不是很好看,于是想著使用easyui的comboTree,雖然效果達(dá)到了,但是風(fēng)格和bootstrap不搭,下面把這兩種方式的效果分享到腳本之家平臺(tái)供大家參考

最近工作中需要用到樹形下拉框,因?yàn)轫?xiàng)目中樹形結(jié)構(gòu)使用的是zTree,然后就百度,結(jié)果出來效果不好看,后來就試著用了easyui的comboTree,雖然比較好看,但是跟整體的bootstrap風(fēng)格有點(diǎn)兒不搭?,F(xiàn)在貼出來兩種方式及效果,以后備用。

方式一,使用zTree

前端代碼:

<div class="form-group"> 
  <label>點(diǎn)擊事件:</label> 
  <input id="selectActionType" class="form-control" onfocus="showActionTypeTree()" onclick="showActionTypeTree()" readonly="readonly" style="border-radius:5px;background-color: white;cursor: default;"/> 
  <input type="hidden" name="actionTypeId" id="actionTypeId"/> 
  <div id="actionTreeContent" class="menuContent" style="border-radius:5px;display: none; z-index:9999;position: absolute; border: 1px #CCC solid; background-color:#f9f9f9;"> 
    <ul id="actionTypeTree" class="ztree" style="margin-top:0;height: 200px;overflow: auto"></ul> 
  </div> 
</div> 

js代碼:

/* 
   * 點(diǎn)擊事件下拉樹的設(shè)置 
   */ 
  var actionTypeSetting = { 
    view: { 
      dblClickExpand: true, 
      showIcon: false, 
      fontCss : {"font-weight":"400","font-size":"20px"} 
    }, 
    data: { 
      key: { 
        name: "text", 
        children: "children" 
      }, 
      simpleData: { 
        enable: true 
      } 
    }, 
    callback: { 
      onClick: actionTypeOnClick 
    } 
  }; 
  /* 
   * 點(diǎn)擊事件下拉樹的點(diǎn)擊事件 
   */ 
  function actionTypeOnClick(e, treeId, treeNode) { 
    $("#actionTypeId").val(treeNode.id); 
    $("#selectActionType").val(treeNode.text); 
  } 
  /* 
   * 初始化點(diǎn)擊事件類型 
   * 
   */ 
  function initActionType() { 
    $.ajax({ 
      async: false, 
      cache: false, 
      type: 'POST', 
      dataType: "json", 
      url: localStorage.getItem("adminPath") + '/touch/typeTable/getActionList?businessTypeId=2', 
      error: function () {//請(qǐng)求失敗處理函數(shù) 
        alert('請(qǐng)求失敗'); 
      }, 
      success: function (data) { //請(qǐng)求成功后處理函數(shù) 
        $.fn.zTree.init($("#actionTypeTree"), actionTypeSetting, data); 
      } 
    }); 
  } 
  /* 
   * 展示點(diǎn)擊事件SelectTree 
   */ 
  function showActionTypeTree() { 
    $.ajax({ 
      url: localStorage.getItem("adminPath") + '/touch/typeTable/getActionList?businessTypeId=2', 
      type: 'POST', 
      dataType: "json", 
      async: false, 
      success: function (data) { 
        $.fn.zTree.init($("#actionTypeTree"), actionTypeSetting, data); 
        var deptObj = $("#selectActionType"); 
        var deptOffset = $("#selectActionType").offset(); 
        $("#actionTreeContent").css({ 
          left: deptOffset.left - 26 + "px", 
          top: deptOffset.top + "px" 
        }).slideDown("fast"); 
        $('#actionTypeTree').css({width: deptObj.outerWidth() + "px"}); 
        var zTree = $.fn.zTree.getZTreeObj("actionTypeTree"); 
        var node = zTree.getNodeByParam("id", $('#actionTypeId').val(), null); 
        zTree.selectNode(node); 
        $("body").bind("mousedown", onBodyDownByActionType); 
      } 
    }); 
  } 
  /* 
   * Body鼠標(biāo)按下事件回調(diào)函數(shù) 
   */ 
  function onBodyDownByActionType(event) { 
    if (event.target.id.indexOf('switch') == -1) { 
      hideActionTypeMenu(); 
    } 
  } 
  /* 
   * 隱藏點(diǎn)擊事件Tree 
   */ 
  function hideActionTypeMenu() { 
    $("#actionTreeContent").fadeOut("fast"); 
    $("body").unbind("mousedown", onBodyDownByActionType); 
  } 

方式二:使用easyui

前端代碼:

<div class="form-group"> 
  <label>點(diǎn)擊事件:</label> 
  <input id="actionTypeId2" name="actionTypeId2" class="form-control" /> 
</div> 

js代碼:

$("#actionTypeId2").combotree({
  url: localStorage.getItem("adminPath") + '/touch/typeTable/getActionList?businessTypeId=2',
  textField:'name',
  onClick: function (node) {
    $("#actionTypeId").val(node.id);
  },
  onSelect: function (node) {
    /**
     * 當(dāng)選中該節(jié)點(diǎn)時(shí)展開該節(jié)點(diǎn),同時(shí)關(guān)閉其他節(jié)點(diǎn)
     */
    if (node.state == "closed") {
      $(this).tree('expand', node.target);
    }
    else {
      var isLeaf = $(this).tree('isLeaf', node.target);
      if (!isLeaf) {
        $(this).tree("collapse", node.target);
      }
    }
  }
});

總結(jié)

以上所述是小編給大家介紹的Easyui和zTree兩種方式分別實(shí)現(xiàn)樹形下拉框,希望對(duì)大家有所幫助,如果大家有任何疑問請(qǐng)給我留言,小編會(huì)及時(shí)回復(fù)大家的。在此也非常感謝大家對(duì)腳本之家網(wǎng)站的支持!

相關(guān)文章

最新評(píng)論