How to Use easyui tree to write simple role permission code, easyuitree

Source: Internet
Author: User

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.

 

Related Article

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.