treelayer function
1 Overview
Syntax: treelayer(TreeObject, Int, Boolean, String)
Definition: Returns the value of the nth level of a tree object TreeObject, which is generally a tree data set, or a tree object such as a drop-down tree or a view tree, and the return value type and separator can be set.
explain in detail:
Object | definition | value |
---|---|---|
TreeObject | tree object | For example: $tree |
Int | Want to get the level value | The top level is 1, the second level is 2, and so on, if there is no return to the bottom |
Boolean | Return value type | false: the return value type is an array, the default value true: the return value type is a string |
String | The separator when the return value type is a string | Expressed in double quotes, the default is a comma: "," |
2. Example
Take a drop-down tree control to display the department hierarchy tree in the FRDemo database as an example to explain the role of the treelayer function.
2.1 Create a new data set
2.1.1 New database query
Create a new ordinary report, create a new data set ds1, the SQL statement is: select * from department, as shown in the following figure:
2.1.2 New tree dataset
Create a new tree data set Tree1, the data set is ds1, the dependent field is did, and the parent tag field is fid, as shown in the following figure:
2.1.3 Data set preview
The preview of the tree dataset effect is shown in the figure below:
2.2 Add controls
Add two controls in the parameter bar: a drop-down tree control and a text control, as shown in the following figure:
2.2.1 Drop-down tree control
Change the control name of the drop-down tree control to tree. Check multiple selection and the result will return to the full hierarchical path.
The data dictionary is automatically constructed, relying on the tree data set Tree1 to construct, and the actual value and display value are both selected as department. As shown below:
2.2.2 Text Control
The control value selection formula of the text control: treelayer($tree, true, "\',\'"), as shown in the figure below:
2.4 Effect preview
Save the template, click Preview, and select Headquarters>Human Resources Department>Human Resources Clerk, Headquarters>Marketing Department>Salesman, as shown in the figure below:
According to the formula filled in the text control value, the return value and separator during preview will be different. The details are shown in the following table:
official | return value | Delimiter | Icon |
---|---|---|---|
treelayer($tree, true, "\',\'") | Human Resources Clerk Salesman |
',' | |
treelayer($tree, 2) | Human Resources Department Marketing Department |
, | |
treelayer($tree, 2, true, "\',\'") | Human Resources Department Marketing Department |
',' |
3. Template download
Click to download the template: treelayer function.cpt