Dapper+linq+json+ztree Build Tree

Source: Internet
Author: User

Dapper Getting collection Entities

<summary>///        Get table Tb_sys_zhuowei all data///        </summary> public        Ienumerable<model_tb_sys_ Zhuowei> Selectall_tb_sys_zhuowei ()        {            using (IDbConnection conn = OpenConnection ())            {                const string query = @ "SELECT * from Tb_sys_zhuowei ORDER by addtime Desc";                Return Conn. query<model_tb_sys_zhuowei> (query, null);            }        }

LINQ handles collections and is processed into JSON by Newtonsoft

Protected string Gettree () {myproject.dataorm dao = new Myproject.dataorm (); ienumerable<myproject.model_tb_sys_zhuowei> list = dao.        Selectall_tb_sys_zhuowei ();                var q = from X in list order X.louceng Group X by X.louceng to G//GROUP by floor                    Select New {name = G.key.tostring () + "floor", open = True, Children = from X2 in g X2.quyu//where X2.louc                               ENG = = G.key Group X2 by X2.quyu to K//GROUP BY region Select New {Name = K.key.length = = 2?                               "Room": K.key + "zone", click = "Loadzw ('" + g.key.tostring () + "-" + K.key + ")" }//select new//{//name = X2.quyu.Length = = 2? "Room": X2.quyu + "zone",//click = "Loadzw ('" + g.key.tostring () + "-" + X2.quyu + "-" + X2.number.ToS        Tring () + "')"//}};        var templist = Q.tolist ();    Return Newtonsoft.Json.JsonConvert.SerializeObject (Templist, Newtonsoft.Json.Formatting.Indented); }
[{    "name": "1 Floor",    "open": true,    "children": [{        "name": "Zone A",        "click": "Loadzw (' 1-a ')"    },    {        "name": "B-zone",        "click": "Loadzw (' 1-b ')"    },    {        "name": "Inter-Package", "click        ": "Loadzw (' 1- BJ ') "    }]},{    " name ":" 2 Floor ","    Open ": True,    " children ": [{        " name ":" Zone A ",        " click ":" Loadzw (' 2-a ') '    }]}]

Front-end Ztree build tree

<script src= ". /.. /js/jquery-1.6.min.js "type=" Text/javascript "></script> <script src=". /.. /js/jquery.ztree.core-3.5.min.js "type=" Text/javascript "></script> <script type=" Text/javascript ">  <!--var setting = {};//var znodes = [//{name: "1 Floor", open:true,//children: [//{Name: "A Zone", click:  "Loadzw (' 1-a ')"},//{name: "Area B", click: "Loadzw (' 1-b ')"},//{name: "C zone", click: "Loadzw (' 1-c ')"}//]//},//{ Name: "2 Floor", open:true,//children: [//{Name: "A zone", click: "Loadzw (' 2-a ')"},//{name: "Zone B", click: "Load                ZW (' 2-b ') "},//{name:" C-Zone ", click:" Loadzw (' 2-c ') "}//]//},//{name:" 3 Floor ", open:true,//  Children: [//{Name: "A zone", click: "Loadzw (' 3-a ')"},//{name: "Zone B", click: "Loadzw (' 3-b ')"},//{name: "C-Zone", click:        "Loadzw (' 3-c ')"}//]//}//]; var znodes = <%=gettree ()%> $ (document). Ready (function () {$.fn.ztree.init ($ ("#treeDemo"), setting, Znodes);        });//--> function Loadzw (KK) {alert (KK); }</script>

Effect



Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.