Using the isBranch() method to determine if a Tree item is a branch or leaf

简介:
The following example shows how you can use the  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 >
        
<![CDATA[
            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.A"   />
                
</ 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 >
    本文转自 OldHawk  博客园博客,原文链接:http://www.cnblogs.com/taobataoma/archive/2008/01/15/1039370.html ,如需转载请自行联系原作者


相关文章
|
10月前
Leetcode 236. Lowest Common Ancestor of a Binary Tree
根据LCA的定义,二叉树中最小公共祖先就是两个节点p和q最近的共同祖先节点,LCA的定义没什么好解释的,主要是这道题的解法。
30 0
|
3月前
Each child in a list should have a unique “key“ prop. Check the render method的报错解决
Each child in a list should have a unique “key“ prop. Check the render method的报错解决
RuntimeError: a view of a leaf Variable that requires grad is being used in an in-place operation.
RuntimeError: a view of a leaf Variable that requires grad is being used in an in-place operation.
2452 0
PAT (Advanced Level) Practice - 1119 Pre- and Post-order Traversals(30 分)
PAT (Advanced Level) Practice - 1119 Pre- and Post-order Traversals(30 分)
117 0
PAT (Advanced Level) Practice - 1119 Pre- and Post-order Traversals(30 分)
|
算法 Android开发
基于branch and bound插入的large neighborhood search
基于branch and bound插入的large neighborhood search
131 0
基于branch and bound插入的large neighborhood search
Identify the logic how BOL node name is categorized into different object type
Identify the logic how BOL node name is categorized into different object type
Identify the logic how BOL node name is categorized into different object type
OPA 15 - find existing item by its type.note
Created by Wang, Jerry, last modified on Nov 08, 2015
OPA 15 - find existing item by its type.note
|
机器学习/深度学习
1064. Complete Binary Search Tree (30)
#include #include #include using namespace std; const int maxn = 1001; vector num(maxn), cbt(maxn); int n, c...
840 0
[LeetCode]--235. Lowest Common Ancestor of a Binary Search Tree
Given a binary search tree (BST), find the lowest common ancestor (LCA) of two given nodes in the BST. According to the definition of LCA on Wikipedia: “The lowest common ancestor is defin
1229 0