1,最簡單的樹 -- 標準 JSON 資料

來源:互聯網
上載者:User

標籤:public

650) this.width=650;" title="搜狗20141225174109.png" alt="wKioL1Sb27WhEW21AAI_xfEedQs353.jpg" src="http://s3.51cto.com/wyfs02/M01/57/7E/wKioL1Sb27WhEW21AAI_xfEedQs353.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 = { 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>

650) this.width=650;" title="搜狗20141225174352.png" alt="wKioL1Sb3HzhdMbkAACXbbFQJc0448.jpg" src="http://s3.51cto.com/wyfs02/M02/57/7E/wKioL1Sb3HzhdMbkAACXbbFQJc0448.jpg" />

 


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

 

本文出自 “程式猿的家--Hunter” 部落格,請務必保留此出處http://962410314.blog.51cto.com/7563109/1596026

1,最簡單的樹 -- 標準 JSON 資料

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.