A mapping table (MAP) class written in JavaScript - continued

zhaozj2021-02-16  51

Orchestration: I want to modify the next article http://dev.9cbs.net/develop/article/27/27499.shtm, 9CBS I don't know how I can't modify it, so I have to re-increase.

It is necessary to explain the purpose of writing this mapping table here. It comes from the inspiration in an ASP project development, which is the management and query of user privileges:

When designing the user user -> role Roles, use "," to separate the multiple roles IDs belong to to determine which roles belonging to the user. On the client interface is two SELECT drop-down boxes, the left is the person User, the role Roles on the right is the role Roles. Select a user in the SELECT on the left, and the corresponding role should be displayed. If you use the user ID to the server query And update the user role, performance and efficiency of the right. Therefore, if you save user-> roles on the client, the specific operation is in the initialization page, save the user and roles of the user's permissions table in the mapping table (Note: The mapping table is in the client, The query is on the server), when you need to query a user (user as a keyword key), when you have a key (role as value), you will directly map the query (LOOKUP), because a user has multiple characters, so The mapping table has also been changed accordingly. The key keyword in the previous mapping table is not allowed to be repeated. Now there is a repetitive keyword, and the return value of the corresponding query will be multiple, so the return value is an array. Types of.

For example, user_a users have two roles of Role_a and Role_B, which can be followed by:

Map.Setat ("User_A", "Role_a");

Map.Setat ("User_a", "role_b");

When you check the role of USER_A, use map.lookup ("user_a") method, which will return an array object, all roles will be saved in this returned array.

The corrected code is as follows: // Note: The code that is commented below exists in the previous version.

Function struct (key, value) {

THIS.KEY = KEY; this.Value = Value;

}

Function set (key, value) {/ * for (var i = 0; i

}

Function Lookup (key) {var arr = new array (); var j = 0; for (var i = 0; i

Function RemoveKey (key) {var v; for (var i = 0; i

Function isempty () {return this.map.Length <= 0;}

Function classmap () {

THIS.MAP = New Array ();

THISLOKUP = Lookup; this.setat = sett; this.removekey = removekey; this.Itcount = getCount; this.isempty = iSempty;}

Finally, I explain that this is only an application, you may apply it to other business logic, if you have a better idea, please contact me yjgx@sina.com.

转载请注明原文地址:https://www.9cbs.com/read-24880.html

New Post(0)