2,最简单的树(自定义图标)

-----后台

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

public partial class _Default : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
    }

    public string GetzNodes()
    {
        StringBuilder sb = new StringBuilder();
        sb.Append("<script>");
        sb.Append("var zNodes =[");
        //*****************************************加入遍历代码
        for (int i = 0; i < 50; i++)
        {
            if (i == 0)
            {
                //父节点
                sb.Append(SetParametes(i.ToString(), "-1", "a", true, true));
            }
            else if(i<10)
                //子节点
                sb.Append(SetParametes(i.ToString(), "0", "b", false));
            else
                //父节点
                sb.Append(SetParametes(i.ToString(), "-1", "a", true));
        }
        //********************************************************
        sb.Append("];");
        sb.Append("</script>");
        return sb.ToString();
    }
    /// <summary>
    /// 设置节点
    /// </summary>
    /// <param name="id">id</param>
    /// <param name="pid">父级id</param>
    /// <param name="name">名称</param>
    /// <param name="parent">是否是父节点?</param>
    /// <param name="open">是否展开?</param>
    /// <returns>返回节点</returns>
    private string SetParametes(string id, string pid, string name, bool parent, bool open = false)
    {
        //父节点的展开图标
        string Popenpath = "../img/1_open.png";
        //父节点的关闭图标
        string Pclosepath = "../img/1_close.png";
        //子节点的图标
        string Cclosepath = "../img/2.png";
        StringBuilder sb = new StringBuilder();
        sb.Append("{");
        sb.AppendFormat("id:{0},", id);
        sb.AppendFormat("pId:{0},", pid);
        sb.AppendFormat("name:\"{0}\",", name);
        if (open)
        {
            sb.AppendFormat("open: true,");
        }
        if (parent)
        {
            sb.AppendFormat("iconOpen: \"{0}\",", Popenpath);
            sb.AppendFormat("iconClose:  \"{0}\"", Pclosepath);
        }
        else
        {
            sb.AppendFormat("icon:\"{0}\"", Cclosepath);
        }
        sb.Append("},");
        return sb.ToString();
    }
}

-----前台

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
    <link href="../css/demo_new.css" rel="stylesheet" type="text/css" />
    <link href="../css/zTreeStyle/zTreeStyle.css" rel="stylesheet" type="text/css" />
    <script src="../js/jquery-1.4.4.min.js" type="text/javascript"></script>
    <script src="../js/jquery.ztree.core-3.5.js" type="text/javascript"></script>
    
    
    
</head>
<%=GetzNodes()%>
<script type="text/javascript">
    var setting = { data: { simpleData: { enable: true} }, callback: { onClick: zTreeOnClick} };
        $(document).ready(function () {
        $.fn.zTree.init($("#treeDemo"), setting, zNodes);
    });
    //显示div
    function showdiv() {
        $("#zhezhao").fadeIn(300);
        $("#treeDemodiv").fadeIn(300);
    }
    //隐藏div
    function closediv() {
        $("#zhezhao").fadeOut(300);
        $("#treeDemodiv").fadeOut(300);
    }
    //展示zTree
    function showZTree() {
        var w = document.documentElement.clientWidth;
        var h = document.documentElement.clientHeight;
        var l = document.documentElement.clientWidth / 2 - $("#treeDemodiv").width() / 2;
        var t = document.documentElement.clientHeight / 2 - $("#treeDemodiv").height() / 2;
        $("#zhezhao").css({ "width": w + "px", "height": h + "px", "filter": "alpha(opacity=25)", "-moz-opacity": "0.25", "-khtml-opacity": "0.25", "opacity": "0.25" });
        $("#treeDemodiv").css({ "left": l + "px", "top": t + "px" });
        showdiv();
    }
    //点击触发事件
    function zTreeOnClick(event, treeId, treeNode) {
        alert(treeNode.id + "," + treeNode.name);
        closediv();
    }
</script>
<body>
    <form id="form1" runat="server">
    
             <input type="button" value="显示" onclick="showZTree()">
            <!------------------Treediv--------------------->
            <div id="treeDemodiv" style="top:0px;left:0px;padding:0px;display:none;margin:0px;;height:470px;width:230px;;position:fixed;z-index:100" class="zTreeDemoBackground left">        
                <ul style="padding:0px;margin:0px;background:#3498DB;height:20px;top:0px;left:0px;"><li style="height:20px;float:right;padding:0px;margin:0px;"><img style="width:19px;;height:19px;z-index:100;cursor:pointer" onclick="$(‘#treeDemodiv‘).fadeOut(300);$(‘#zhezhao‘).fadeOut(300);" src="../img/yzfalse.png" /></li></ul>
                <ul id="treeDemo" style="padding:0px;margin:0px;height:448px;width:228px;z-index:100;background:#fff" class="ztree"></ul>
            </div>
            <div id="zhezhao" style="top:0px;left:0px;display:none;filter:alpha(opacity=25);-moz-opacity:0.25;-khtml-opacity: 0.25;opacity: 0.25;position:fixed;background:#000;z-index:9"></div>
            <!------------------Treediv--------------------->
          
    </form>
</body>
</html>

整合包下载:http://down.51cto.com/data/1967063

时间: 2025-01-25 16:54:16

2,最简单的树(自定义图标)的相关文章

Unreal Engine 4 C++ 为编辑器中Actor创建自定义图标

有时候我们创建场景的时候,特定的Actor我们想给它一个特定的图标,便于观察.比如这样: 实现起来也很简单,需要编写C++代码: 我们创建一个Actor,叫AMyActor,它包含一个Sprite(精灵),这个精灵负责显示自定义图标:代码如下 #pragma once #include "GameFramework/Actor.h" #include "Components/BillboardComponent.h" #include "MyActor.g

Android ToolBar自定义图标,关联DrawerLayout

Android5.0出现了一个可以代替ActionBar的控件ToolBar,使用更加灵活,一般我们使用ToolBar来和DrawerLayout配合使用,官方提供了一个开关类ActionBarDrawerToggle,来实现ToolBar和DrawerLayout的关联,但是 有时根据我们的需求需要更改左侧的图标,不在需要系统默认的三条杠的图标同时点击图标还想要DrawerLayout的侧拉页面出来,下面讲解两种不同的方式 一:通过代码来实现改变ToolBar的图标 public class

【简单线段树】I Hate It (求范围内最大)

I Hate It Time Limit: 9000/3000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 53477    Accepted Submission(s): 21005 Problem Description 很多学校流行一种比较的习惯.老师们很喜欢询问,从某某到某某当中,分数最高的是多少. 这让很多学生很反感.不管你喜不喜欢,现在需要你做的是,就是按照老师的

一个简单的jsp自定义标签

学到了一个简单的jsp自定义标签,后面有更多的例子,会更新出来: 例子1: 步骤: 1.编写标签实现类: 继承javax.servlet.jsp.tagext.SimpleTagSupport; 重写doTag,实现在网页上输出: 2.在web-inf目录或其子目录下,建立helloword.tld文件,即自定义标签的说明文件 注意:标签处理类必须放在包中,不能是裸体类:不需要修改web.xml: //tld: tag lib description 标签库描述 java代码: package

hihocoder 1192 简单的树嵌入 (树上DFS 构造 好题)

#1192 : 简单的树嵌入 时间限制:10000ms 单点时限:1000ms 内存限制:256MB 描述 给定一棵n个点的无权树.定义两点i,?j(0?≤?i,?j?≤?n?-?1)间的距离d(i,?j)为两点间树上最短路径的长度(边数). 我们需要将这n个点映射到中的向量v0?=?(v0,?0,?...,?v0,?m?-?1),?...,?vn?-?1?=?(vn?-?1,?0,?...,?vn?-?1,?m?-?1).定义两向量vi,?vj间的L1距离为 我们希望对于所有0?≤?i,?j?

浅谈DevExpress&lt;五&gt;:TreeList简单的美化——自定义单元格,加注释以及行序号

今天就以昨天的列表为例,实现以下效果:预算大于110万的单元格突出显示,加上行序号以及注释,如下图: 添加行序号要用到CustomDrawNodeIndicator方法,要注意的是,取得的节点索引是从0开始的,所以要+1以便第一行从一开始算起. private void treeList1_CustomDrawNodeIndicator(object sender, CustomDrawNodeIndicatorEventArgs e) { TreeList tree = sender as D

在Eclipse中JFrame自定义图标可以显示,但是导出JAR之后无法显示

在我的项目中,一开始我使用这种方式构造图片路径,然后将其设置到JFrame中即可以显示自定义图标 String imagePath = System.getProperty("user.dir") + "/image/icon.png";// 构造图片的路径 Image imageIcon = Toolkit.getDefaultToolkit().getImage(imagePath); jFrame.setIconImage(imageIcon); 项目路径如下

ionic2中使用自定义图标

在ionic2中使用自定义图标,如iconfont(阿里巴巴矢量图标). 先在http://www.iconfont.cn/ 中找到自己需要的图标,然后将图标加入购物车,然后下载该图标. 下载完成后解压,打开文件demo_unicode.html可以看到它提供的使用方法,我们在ionic2中按照以下方法使用: 1.在项目的assets目录下新建fonts文件夹,然后将下载解压后的iconfont.woff.iconfont.ttf.iconfont.svg.iconfont.eot添加到font

JSP等网站【创建带自定义图标的桌面快捷方式】

原理解析:1.打开网页 2.打开网页的exe自定义图标 URL= "http://www.gaoxinshangcheng.com/" Call RunApp(URL) Call OnScriptExit() Sub OnScriptExit() Hwnd = Plugin.Window.Find(0, "桌面快捷方式Exe运行标题") Call Plugin.Window.Close(Hwnd) End Sub 有附件可用.

HDU 1247 简单字典树

Hat’s Words Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 7359    Accepted Submission(s): 2661 Problem Description A hat’s word is a word in the dictionary that is the concatenation of exactly