How to Use easyui tree to write simple role permission code, easyuitree
First, each administrator must have a role:
Roles can operate on multiple columns. In this case, we can select multiple columns by tree:
Js Code on the page:
$ ('# Permission '). dialog ({title: 'topic authorization', closed: false}); $ ('# rtt '). tree ({url: 'ashx/RoleService. ashx? Action = RoleTree & Rid = '+ raw. ID, method: 'get', animate: true, checkbox: true}); $ ('# rid '). val (raw. ID );
A dialog pop-up is used to input a role number in ashx.
C # code:
case "RoleTree": string Rid = context.Request.Params["Rid"]; int Roleid = Convert.ToInt32(Rid); List<tree> treelist = getChildren("Angel_Admin_Navigation", "0", Roleid); Newtonsoft.Json.Converters.IsoDateTimeConverter timeConverter = new Newtonsoft.Json.Converters.IsoDateTimeConverter(); timeConverter.DateTimeFormat = "yyyy'-'MM'-'dd"; string ResJsonStr = JsonConvert.SerializeObject(treelist, Formatting.Indented, timeConverter); context.Response.ContentType = "text/plain"; context.Response.Clear(); context.Response.Write(ResJsonStr);
If case is an action parameter, you don't need to talk about it!
Now let's take a look at how to write the output tree data:
// Tree recursively calls public List <tree> getChildren (string tableName, string fid, int RoleId) {DBHelperSql Dbhelper = new DBHelperSql (); list <tree> list = new List <tree> (); DataTable dt = Dbhelper. getDataTable (tableName, "ParentId = '" + fid + "'"); if (dt. rows. count> 0) {for (int I = 0; I <dt. rows. count; I ++) {tree = new tree (); tree. id = dt. rows [I] ["NavName"]. toString (); tree. text = dt. rows [I] ["TitleName"]. toString (); if (OperateBll. isRoleoperateDataExist (dt. rows [I] ["NavName"]. toString (), RoleId) {tree. @ checked = true;} tree. children = getChildren (tableName, dt. rows [I] ["id"]. toString (), RoleId); list. add (tree) ;}} else list = null; return list;} // tree attribute public class tree {public string id {get; set;} public string text {get; set ;}public bool @ checked {get; set ;}public List <tree> children {get; set ;}}
A recursive method is implemented. Call this method for the json output above.
Final display page
Sometimes easyui is used to it very well. The above code is expected to help those who need it.