First, View:
1. Defining an input control
<input id= "ParentID" name= "ParentID" >
2. Binding Combotree
$ (' #ParentId '). Combotree ({url: "/action/getmenutreedata/", Method: "Post", Lines:true,required:true,onclick: function (node) {
Automatically generates the sort number $.post ("/action/getmenudisorder/", {pId:node.id}, function (data) {$ ("#DisOrder"). val (data);});
Automatically generates the current level $.post ("/action/getmenudislevel/", {pId:node.id}, function (data) {$ ("#DisLevel"). val (data);});});
Second, Controller:
[Httppost]public actionresult Getmenutreedata () {//fetch from the data dictionary the ID number corresponding to the menu var dic = _dictionaryservice.single (O-O. Name = = "Menu" && o.isdeleted = = False); var menuId = dic. id;//Query all menu information var menus = _actionservice.where (o = o.isdeleted = False && O.operationtype = MenuId && O.isshow = = True, O = O.disorder). ToList ();//Get root node information RSCC.Model.TreeNode rootNode = _actionservice.single (o = = O.parentid = 0). Tonode ();//3, depending on the ID of the root node, queries all of its child nodes Rootnode.children = fillsonnodes (menus, rootnode.id); return Content ("[" + Operationcontext.tojson (RootNode) + "]");}
<summary>///Recursive generation of child node collections//</summary>///<param name= "Listpermission" ></param>///< param name= "ParentID" ></param>///<RETURNS></RETURNS>LIST<RSCC. Model.treenode> Fillsonnodes (LIST<RSCC. model.action> list, int parentid) {LIST<RSCC. model.treenode> sonnodes = null;//Loop Permission collection, find child permissions foreach (RSCC. Model.action m in list) {//Find child permissions if (M.parentid = = ParentID) {//Instantiate child node collection if (sonnodes = = null) Sonnodes = new LIST<RSCC. Model.treenode> ();//Transfer Child permissions to child nodes RSCC.Model.TreeNode Sonnode = M.tonode ();//Add child nodes to the child Nodes Collection Sonnodes.add (sonnode);// Recursively finds child node sets for child nodes Sonnode.children = fillsonnodes (list, sonnode.id);}} return sonnodes;}
Third, the display effect:
Example of using Easyui Combotree