Wg_listtotree Widget converts a list array to a tree using JavaScript

Source: Internet
Author: User
Tags javascript array

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

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.