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.