Generates a JSON string code for the tree structure.

Source: Internet
Author: User

The framework uses EF6.0. You can use Newtonsoft.Json.dll (Baidu Search) for the returned value to serialize the returned value to a Json string, if the following value is used Jsonconvert.serializeobject ( Functiontree), don't say anything, on the instance code

/// <summary>        ///Init tree/// </summary> /// <returns></returns>         PublicList<functioninfomapping>Loadtree () {List<FunctionInfoMapping> Listtree =Inittree (); returnListtree; //return Jsonconvert.serializeobject (list);        }        /// <summary>        ///init tree Find top Menu/// </summary>        /// <returns></returns>        PrivateList<functioninfomapping>Inittree () {Rightscontext rightcontext=NewRightscontext (); varTreelist = ( fromAinchdb. Functioninfoes Join Binchdb. Functioninfoes on A.parentid equals B.functionidSelect Newfunctioninfomapping {ID=A.functionid, Title=A.functionname, Functiontype=A.functiontype, ParentID=B.functionid, ParentName=B.functionname, Functionpath=A.functionpath, Description=a.description, SortId=A.sortid,}). Union ( fromAinchdb. FunctioninfoeswhereA.parentid = =-1                            Select Newfunctioninfomapping {ID=A.functionid, Title=A.functionname, Functiontype=A.functiontype, ParentID= -1, ParentName="", Functionpath=A.functionpath, Description=a.description, SortId=A.sortid,}); varNewTree =treelist.union (treelist); //list<functioninfomapping> reelist= treelist.tolist<functioninfomapping> ()List < functioninfomapping > RootNode =NewList<functioninfomapping>(); foreach(varPlistinchNewtree.where (t = T.parentid = =-1) {functioninfomapping node=Newfunctioninfomapping (); Node.id=plist.id; Node. Title=plist.                Title; Node. Functiontype=plist.                Functiontype; Node. ParentID=plist.                ParentID; Node. ParentName=plist.                ParentName; Node. Functionpath=plist.                Functionpath; Node. Description=plist.                Description; Node. SortId=plist.                SortId; Node. Nodes= Createchildtree (newtree.asqueryable<functioninfomapping>(), node);            Rootnode.add (node); }            returnRootNode; }        /// <summary>        ///Recursive/// </summary>        /// <param name= "treelist" ></param>        /// <param name= "JT" ></param>        /// <returns></returns>        PrivateList<functioninfomapping> Createchildtree (iqueryable<functioninfomapping>treelist, functioninfomapping parentid) {            intkeyID = parentid.id;//Root IDList<functioninfomapping> nodeList =NewList<functioninfomapping>(); varChildren = treelist.where (t = = T.parentid = =keyID); foreach(varChlinchchildren) {functioninfomapping node=Newfunctioninfomapping (); Node.id=chl.id; Node. Title=CHL.                Title; Node. Functiontype=CHL.                Functiontype; Node. ParentID=CHL.                ParentID; Node. ParentName=CHL.                ParentName; Node. Functionpath=CHL.                Functionpath; Node. Description=CHL.                Description; Node. SortId=CHL.                SortId; Node. Nodes=Createchildtree (treelist, node);            Nodelist.add (node); }            returnnodeList; }

The structure returned is as follows

[{"id": 2, "title": "Fundamental", "functiontype": 1, "ParentID":-1, "ParentName"        : "", "Functionpath": "/html/fundamental", "description": "Fundamental menu link", "SortID": 0,        "Nodes": []}, {"id": 3, "title": "Auth Manager", "Functiontype": 1, "ParentID":-1, "ParentName": "", "Functionpath": "/html/auth", "description": "Auth Manager Link", "SortID" : 0, "nodes": [{"id": 4, "title": "Role Manager", "functi Ontype ": 2," ParentID ": 3," ParentName ":" Auth Manager "," Functionpath ":"/ht Ml/auth/roles.html "," description ":" Roles Manager Page "," SortID ": 0," nod                        Es ": [{" id ": Ten," title ":" Add Role ", "Functiontype": 3,                        "ParentID": 4, "ParentName": "Role Manager", "functi Onpath ": null," description ": null," SortID ": 0," nod Es ": []}, {" id ":" title ":" Delet E role "," Functiontype ": 3," ParentID ": 4," Parentnam                        E ":" Role Manager "," Functionpath ": null," description ": null,                 "SortID": 0, "Nodes": []}]}, { "id": 5, "title": "Page Manager", "Functiontype": 2, "Parenti                D ": 3," ParentName ":" Auth Manager "," Functionpath ":"/html/auth/pages.html ", "description": "Pages PErmission Manager Page "," SortID ": 0," Nodes ": []}]} 

Generates a JSON string code for the tree structure.

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.