Using the isbranch () method to determine if a tree item is a branch or leaf

Source: Internet
Author: User
The following example shows how you can use Isbranch () Method to determine if a specific node in a tree control is a branch (folder) or leaf (item ). <? XML version = "1.0" encoding = "UTF-8" ?>
<! -- Http://blog.flexexamples.com/2007/11/30/using-the-isbranch-method-to-determine-if-a-tree-item-is-a-branch-or-leaf/ -->
< MX: Application Xmlns: MX = "Http://www.adobe.com/2006/mxml"
Layout = "Vertical"
Verticalalign = "Middle"
Backgroundcolor = "White" >

mx: script >

Import MX. Events. listevent;

Private function tree_itemclick (EVT: listevent): void {
VaR itemisbranch: Boolean = tree. datadescriptor. isbranch (tree. selecteditem );
LBL. Text = itemisbranch. tostring ();
}

Private function tree_labelfunc (item: XML): String {
VaR returnstr: String = item. @ label;
VaR itemisbranch: Boolean = tree. datadescriptor. isbranch (item );
If (itemisbranch ){
Returnstr + = "(Branch )";
}
Return returnstr;
}
]>
</ MX: script >

< MX: XML ID = "Xmldp" >
< Node >
< Node Label = "1.a"   />
< Node Label = "1. B"   />
< Node Label = "1.c" >
< Node Label = "1. c. I"   />
< Node Label = "1. C. II"   />
< Node Label = "1. C. III"   />
< Node Label = "1. C. IV"   />
< Node Label = "1. C. V"   />
</ Node >
< Node Label = "1.d"   />
< Node Label = "1.e" >
< Node Label = "1. e. I"   />
< Node Label = "1. E. II"   />
< Node Label = "1. E. III" >
< Node Label = "1. E. III."   />
</ Node >
< Node Label = "1. E. IV"   />
</ Node >
< Node Label = "1.f"   />
</ Node >
</ MX: XML >

< MX: applicationcontrolbar Dock = "True" >
< MX: Form Stylename = "Plain" >
< MX: formitem Label = "Isbranch ():" >
< MX: Label ID = "LBL" Fontweight = "Bold"   />
</ MX: formitem >
</ MX: Form >
</ MX: applicationcontrolbar >

< MX: Tree ID = "Tree"
Dataprovider = "{Xmldp }"
Labelfunction = "Tree_labelfunc"
Showroot = "False"
Width = "50%"
Rowcount = "6"
Itemclick = "Tree_itemclick (event );"   />

</MX: Application>

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.