Brief introduction:
The tree menu is often encountered in B/s programming, but not every tree plugin supports the list type JSON data, and because background conversion is not as front-end saving resources , so make this plug-in;
Main functions:
1. You can customize the property name;
2. Can be multi-field sorting;
Note: This plugin has no de-duplication function , so the data may be duplicated, please repeat after the use of the line;
Example:
Results:
Note: For useless interference data, plug-ins will be ignored;
How to use:1. Import the relevant JS file;
2. Call the function, pass in the parameter;
Function name: Wg_listtotree (param), where Param is a JSON object containing the specific contents of the parameters;
List,inparams,outparams,sort four JSON objects, respectively, representing data, input parameters, output parameters and sorting parameters;
After the function executes, it returns a tree-formatted JSON object;
Parameter description:list: A JSON array, JavaScript array; format: [{id:2,pid:1,text: ' 2 ', TT: ' 222 '},{...}]
Inparams: a JSON object that contains three attributes;
{pid: "pid",//the name of the parent node's number
rootid:-1,//value of the root node
ID: ' ID ',//The name of the current node's number
}
Outparams: a JSON object that can contain multiple attributes;
{
Children: "Children",//name of the child node array
PID: "pid",//the name of the parent node's number
ID: ' ID ',//name of the current node number
KK: ' qwe ',//list array object, itself has a property called KK, want to output the name of ' Qwe ';
State: ' state ',//with KK
}//Note: The other list has attributes, which are reserved accordingly .... Theory
Sort: a JSON object, a user sort, not specified, or an incoming null representation is not sorted, and sorting consumes a certain resource
{
orderby:["pid", "id"],//the sort field specified in the Sort, and the field name one by one that is output in Outparams, which is used to sort by PID, if equal, then by ID field
Sort: "ASC",//Sort by, ASC means ascending, other means descending
}
Plugin Download: Click to open link
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
Wg_listtotree Widget converts a list array to a tree using JavaScript