iis服务器助手广告广告
返回顶部
首页 > 资讯 > 后端开发 > Python >3,最简单的树(不显示图标)
  • 166
分享到

3,最简单的树(不显示图标)

最简单图标 2023-01-31 06:01:45 166人浏览 安东尼

Python 官方文档:入门教程 => 点击学习

摘要

 -----后台using System; using System.Collections.Generic; using System.Linq; using System.WEB; using System.Web.UI; using 

wKioL1Sb3izAwE5vAAI_xfEedQs501.jpg

 

-----后台

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 < 100; i++)
        {
            if (i > 50)
            {
                sb.Append(SetParametes(i.ToString(), "1", "b"));
            }
            else
            sb.Append(SetParametes(i.ToString(), "-1", "a"));
        }
        //********************************************************
        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="open">是否展开?</param>
    /// <returns>返回节点</returns>
    private string SetParametes(string id, string pid, string name,bool open=false)
    {
        StringBuilder sb = new StringBuilder();
        sb.Append("{");
        sb.AppendFORMat("id:{0},",id);
        sb.AppendFormat("pId:{0},",pid);
        if (open)
        {
            sb.AppendFormat("name:\"{0}\",", name);
            sb.Append("open: true");
        }
        else
        {
            sb.AppendFormat("name:\"{0}\"", name);
        }
        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 = { view: {showIcon: showIconForTree}, 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);
    }
    function showIconForTree(treeId, treeNode) {
        return !treeNode.isParent;
    };
    //展示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>

 

wKioL1Sb3oTyuDdEAACHPf1iSQo745.jpg

 


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

--结束END--

本文标题: 3,最简单的树(不显示图标)

本文链接: https://www.lsjlt.com/news/189803.html(转载时请注明来源链接)

有问题或投稿请发送至: 邮箱/279061341@qq.com    QQ/279061341

本篇文章演示代码以及资料文档资料下载

下载Word文档到电脑,方便收藏和打印~

下载Word文档
软考高级职称资格查询
编程网,编程工程师的家园,是目前国内优秀的开源技术社区之一,形成了由开源软件库、代码分享、资讯、协作翻译、讨论区和博客等几大频道内容,为IT开发者提供了一个发现、使用、并交流开源技术的平台。
  • 官方手机版

  • 微信公众号

  • 商务合作