Dapper + linq + json + ztree construction tree

Source: Internet
Author: User

Dapper obtains the collection entity

////// Obtain all data of table tb_sys_zhuowei ///Public IEnumerable
 
  
SelectAll_tb_sys_zhuowei () {using (IDbConnection conn = OpenConnection () {const string query = @ "select * from tb_sys_zhuowei order by addtime desc"; return conn. Query
  
   
(Query, null );}}
  
 

Use Newtonsoft

Protected string GetTree () {MyProject. DataOrm dao = new MyProject. DataOrm (); IEnumerable
 
  
List = dao. selectAll_tb_sys_zhuowei (); var q = from x in list orderby x. louceng group x by x. louceng into g // select new {name = g by floor group. key. toString () + "", open = true, children = from x2 in g orderby x2.quyu // where x2.louceng = g. key group x2 by x2.quyu into k // group by region select new {name = k. key. length = 2? "Compartment": k. key + "zone", click = "loadzw ('" + g. key. toString () + "-" + k. key + "')"} // select new // {// name = x2.quyu. length = 2? "Compartment": x2.quyu + "zone", // click = "loadzw ('" + g. key. toString () + "-" + x2.quyu + "-" + x2.number. toString () + "')" //}; var templist = q. toList (); return Newtonsoft. json. jsonConvert. serializeObject (templist, Newtonsoft. json. formatting. indented );}
 
[{"Name": "1st Floor", "open": true, "children": [{"name": "Area A", "click ": "loadzw ('1-a')"}, {"name": "Zone B", "click": "loadzw ('1-B ')"}, {"name": "compartment", "click": "loadzw ('1-BJ ')"}] },{ "name": "Floor 2 ", "open": true, "children": [{"name": "Area A", "click": "loadzw ('2-a')"}]

Front-end ztree construction 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 ">
 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.