zTree树形插件异步加载方法详解,ztree树形异步详解

正文实例为大家享受了zTree树形插件异步加载,Struts2框架,供大家参考,具体内容如下

<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>异步加载</title>
<link rel="stylesheet"
  href="${pageContext.request.contextPath}/zTree_v3-master/css/demo.css">
<link rel="stylesheet"
  href="${pageContext.request.contextPath}/zTree_v3-master/css/zTreeStyle/zTreeStyle.css">
<script type="text/javascript"
  src="${pageContext.request.contextPath}/jquery-2.1.1.min.js"></script>
<script type="text/javascript"
  src="${pageContext.request.contextPath}/zTree_v3-master/js/jquery.ztree.core.min.js"></script>
<script type="text/javascript">
  var setting = {
    async : {
      enable : true,
      url : "${pageContext.request.contextPath}/ztreeAction!getMenusById.jhtml",
      autoParam : [ "id" ],
    //dataFilter : filter
    },
    data : {
      key : {
        url : "xUrl"
      },
      simpleData : {
        enable : true,
        pIdKey : "pid"
      }
    },

  };
  $(document).ready(function() {
    $.fn.zTree.init($("#treeDemo"), setting);
  });
</script>



</head>
<body>
  <div class="ztree"
    style="width: 20%; height: 500px; padding-top: 10px; float: left; border: 1px solid #FF0000;">
    <ul id="treeDemo"></ul>
  </div>

</body>
</html>

地点吧,是jsp页面包车型客车代码,因为是纯插件测验,可以直接复制过去应用的,

action层代码,能够一向复制利用

public void getMenusById(){
    List<Ztree> list=null;
    try {
      list=ztreeService.getMenusById(ztree);
    } catch (Exception e) {
      e.printStackTrace();
    }
    super.writeJson(list);
}

public List<Ztree> getMenusById(Ztree ztree) throws Exception;
//接口

//service代码,几本都可以复制使用


package com.jk.service.impl;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import com.jk.dao.ZtreeDao;
import com.jk.model.Ztree;
import com.jk.service.ZtreeService;
@Repository("ztreeService")
public class ZtreeServiceImpl implements ZtreeService {

  @Autowired
  private ZtreeDao ztreeDao;

  @Override
  public List queryList(Ztree ztree) throws Exception {
    String hql=" from Ztree where 1=1 ";
    Map<String, Object> params = new HashMap<String, Object>();
//传的对象是否为空,拼接sql+id
      if(ztree.getId()!=null){
        hql+=" and id = :id ";
        params.put("id",ztree.getId());
      }


    return ztreeDao.queryList(hql, params);
  }
  //递归查询
  @Override
  public List<Ztree> getMenusById(Ztree ztree) throws Exception {
    String hql=" from Ztree where 1=1 ";
    Map<String,Object> params=new HashMap<String,Object>();
    if(ztree.getId()==null||ztree.getId().equals("")){
      hql+=" and pid is null ";
    }else{
      hql+= " and pid = :id ";
      params.put("id",ztree.getId());
    }
    List<Ztree> queryZtree = ztreeDao.queryList(hql, params);
    List<Ztree> list=new ArrayList<Ztree>();
    for(Ztree ztree2:queryZtree){
      if(queryBoolean(ztree2)){
        ztree2.setIsParent("true");
      }
      list.add(ztree2);
    }
    return list;
  }
  //熟悉递归的朋友应该可以看懂,我就不解释了,我也聊不清楚这个递归,不误导了,代码在这,可以复制进去直接运行,
  public boolean queryBoolean(Ztree ztree) throws Exception{
    boolean flag=false;
    String hql= " from Ztree where pid = :id ";

    Map<String,Object> params=new HashMap<String,Object>();
    params.put("id", ztree.getId());
    List<Ztree> queryZtree = ztreeDao.queryList(hql, params);
    if(queryZtree!=null&&queryZtree.size()>0){
      flag=true;
    }
    return flag;
  }


}

dao层就不用写了呢,只是一个查询,上边作者把ztree的表字段附上

永利集团304手机版 1

上述正是本文的全部内容,希望对大家的学习抱有援助,也愿意我们多多援助帮客之家。

永利集团304手机版,
本文实例为大家大快朵颐了zTree树形插件异步加载,Struts2框架,供我们参谋,具体内容如下…

永利集团304手机版 2

永利集团304手机版 3

你大概感兴趣的篇章:

  • jquery zTree异步加载轻易实例分享
  • struts2+jquery+json完成异步加载数据(自写)
  • JQuery异步加载Infiniti下拉框级联成效落成示例
  • jquery ztree实现下拉树形框使用到了json数据
  • 最佳树Jquery插件zTree的常用功用特色总计
  • Jquery树插件zTree用法入门教程
  • json+jQuery实现的Infiniti级树形菜单功效代码
  • 轻松学习jQuery插件EasyUI EasyUI创制树形菜单
  • JQuery ztree 异步加载实例批注
  • jquery ztree实现树的查找作用

本文实例解说了jQuery使用zTree插件达成树形菜单和异步加载,何况可以开展编写制定,分享…

dao层就绝不写了啊,只是二个查询,上面笔者把ztree的表字段附上

您大概感兴趣的稿子:

  • jquery
    zTree异步加载、模糊寻觅简单实例分享
  • Jquery zTree
    树控件异步加载操作
  • JQuery
    ztree带筛选、异步加载实例解说
  • JQuery ztree
    异步加载实例讲明
  • jquery
    zTree异步加载简单实例分享
  • jQuery zTree
    异步加载增添子节点重复难点

jQuery使用zTree插件达成树形菜单和异步加载,jqueryztree

本文实例讲授了jQuery使用zTree插件完结树形菜单和异步加载,并且能够拓宽编写制定,分享给大家供大家参考,具体内容如下

效果图:

永利集团304手机版 4

一、HTML代码

<html>
<head runat="server">
 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
 <title></title>
 <link href="zTree/css/demo.css" rel="stylesheet" />
 <link href="zTree/css/zTreeStyle/zTreeStyle.css" rel="stylesheet" />
 <script src="zTree/js/jquery-1.4.4.min.js"></script>
 <script src="zTree/js/jquery.ztree.core-3.5.js"></script>
 <script src="zTree/js/jquery.ztree.excheck-3.5.js"></script>
 <script src="zTree/js/jquery.ztree.exedit-3.5.js"></script>
  <script type="text/javascript">
   var setting = {
  async: {
   enable: true,
   url: "AjaxPage/GetAjax.aspx?z=sdfww234edfsd",
   autoParam: ["id"],
   dataFilter: filter,
   contentType: "application/json",
   type:"get"
  },
  view: {
   expandSpeed: "",
   addHoverDom: addHoverDom,
   removeHoverDom: removeHoverDom,
   selectedMulti: false
  },
  check: {
   enable: true
  },
  edit: {
   enable: true
  },
  data: {
   simpleData: {
    enable: true
   }
  },
  callback: {
   beforeRemove: beforeRemove,
   beforeRename: beforeRename,
  }
 };
 function filter(treeId, parentNode, childNodes) {
  if (!childNodes) return null;
  for (var i = 0, l = childNodes.length; i < l; i++) {
   childNodes[i].name = childNodes[i].name.replace(/\.n/g, '.');
  }
  return childNodes;
 }
 function beforeRemove(treeId, treeNode) {
  var zTree = $.fn.zTree.getZTreeObj("treeDemo");
  zTree.selectNode(treeNode);
  return confirm("确认删除 节点 -- " + treeNode.name + " 吗?");
 }
 function beforeRename(treeId, treeNode, newName) {
  if (newName.length == 0) {
   alert("节点名称不能为空.");
   return false;
  }
  return true;
 }

 var newCount = 1;
 function addHoverDom(treeId, treeNode) {
  var sObj = $("#" + treeNode.tId + "_span");
  if (treeNode.editNameFlag || $("#addBtn_" + treeNode.tId).length > 0) return;
  var addStr = "";
  sObj.after(addStr);
  console.log("add  " + "#addBtn_" + treeNode.id);
  var btn = $("#addBtn_" + treeNode.tId);
  if (btn) btn.bind("click", function () {
   var zTree = $.fn.zTree.getZTreeObj("treeDemo");
   zTree.addNodes(treeNode, { id: (100 + newCount), pId: treeNode.id, name: "new node" + (newCount++) });
   return false;
  });
 };
 function removeHoverDom(treeId, treeNode) {
  console.log("remove  " + "#addBtn_" + treeNode.id);
  $("#addBtn_" + treeNode.tId).unbind().remove();
 };
 $(document).ready(function () {
  $.fn.zTree.init($("#treeDemo"), setting);
 });
  </script>
</head>
<body>
 <ul id="treeDemo" class="ztree" style="width: 560px; overflow: auto;"></ul>
</body>
</html>

二、异步央浼的后台数据:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace CssStudyWeb.AjaxPage
{
 public partial class GetAjax : System.Web.UI.Page
 {
  protected void Page_Load(object sender, EventArgs e)
  {
   if (Request.QueryString["z"] == "sdfww234edfsd")//根据会员卡号,查询会员卡信息
   {
    StringBuilder sb = new StringBuilder();
    sb.Append("[");
    sb.Append("{\"id\":\"1\",\"name\":\"销售单管理\",\"pId\":\"0\"},");
    sb.Append("{\"id\":\"101\",\"name\":\"销售单列表\",\"pId\":\"1\"},");
    sb.Append("{\"id\":\"102\",\"name\":\"销售单综合查询\",\"pId\":\"1\"},");

    sb.Append("{\"id\":\"2\",\"name\":\"系统管理\",\"pId\":\"0\"},");
    sb.Append("{\"id\":\"103\",\"name\":\"权限组管理\",\"pId\":\"2\"},");
    sb.Append("{\"id\":\"104\",\"name\":\"权限菜单管理\",\"pId\":\"2\"}");
    sb.Append("]");
    Response.Write(sb.ToString());
   }
  }
 }
}

上述便是zTree插件完结树形菜单和异步加载的漫天代码,希望对大家的上学抱有辅助。

你也许感兴趣的稿子:

  • webpack中援用jquery的简要达成
  • Webpack 完成 AngularJS
    的推迟加载
  • Vue.js中用webpack合并打包七个零部件并贯彻按需加载
  • Bootstrap Tree
    View不难而雅致的树结构组件实例深入分析
  • 浅析webpack
    怎么样优雅的选拔tree-shaking(摇树优化)

本文实例批注了jQuery使用zTree插件完成树形菜单和异步加载,况且可以拓宽编辑,分享给大家供大家参谋,具体内容如下